@kheopskit/core 6.0.1 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/ethereum.js +56 -7
- package/dist/ethereum.js.map +1 -1
- package/dist/ethereum.mjs +57 -8
- package/dist/ethereum.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @kheopskit/core
|
|
2
2
|
|
|
3
|
+
## 6.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#196](https://github.com/kheopskit/kheopskit/pull/196) [`843ec8e`](https://github.com/kheopskit/kheopskit/commit/843ec8e8d28d9607eb913c590a6925f12880317d) Thanks [@0xKheops](https://github.com/0xKheops)! - Fixed: an injected Ethereum wallet's accounts and chain show in the same `kheopskit$` emission that shows the wallet connected, on a user connect and on a reload's reconnect, instead of one emission later. A wallet's late `eth_accounts` or `eth_chainId` answer no longer overwrites an `accountsChanged`, `chainChanged` or `connect` event sent after it was asked. A connect no longer waits forever for a wallet that never answers `eth_chainId`: after 2 seconds its accounts show without a chain.
|
|
8
|
+
|
|
3
9
|
## 6.0.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/ethereum.js
CHANGED
|
@@ -23,11 +23,43 @@ const toCaipNetworkId = (value) => {
|
|
|
23
23
|
const chainId = normalizeEvmChainId(value);
|
|
24
24
|
return chainId === void 0 ? void 0 : `eip155:${chainId}`;
|
|
25
25
|
};
|
|
26
|
+
const lastReported = /* @__PURE__ */ new WeakMap();
|
|
27
|
+
const CHAIN_ANSWER_TIMEOUT_MS = 2e3;
|
|
28
|
+
const readChainId = (provider) => (0, rxjs.firstValueFrom)((0, rxjs.race)(provider.request({ method: "eth_chainId" }).then(normalizeEvmChainId, () => void 0), (0, rxjs.timer)(CHAIN_ANSWER_TIMEOUT_MS).pipe((0, rxjs.map)(() => void 0))));
|
|
29
|
+
const requestAccountsOnChain = async (provider) => {
|
|
30
|
+
const accountChanges = [];
|
|
31
|
+
const chainChanges = [];
|
|
32
|
+
const handleAccountsChanged = (addresses) => {
|
|
33
|
+
accountChanges.push(addresses);
|
|
34
|
+
};
|
|
35
|
+
const handleChainChanged = (chainId) => {
|
|
36
|
+
chainChanges.push(normalizeEvmChainId(chainId));
|
|
37
|
+
};
|
|
38
|
+
provider.on("accountsChanged", handleAccountsChanged);
|
|
39
|
+
provider.on("chainChanged", handleChainChanged);
|
|
40
|
+
try {
|
|
41
|
+
const addresses = await provider.request({ method: "eth_requestAccounts" });
|
|
42
|
+
const chainChangesBeforeRead = chainChanges.length;
|
|
43
|
+
const chainId = await readChainId(provider);
|
|
44
|
+
lastReported.set(provider, {
|
|
45
|
+
addresses: accountChanges.at(-1) ?? addresses,
|
|
46
|
+
chainId: chainChanges.length > chainChangesBeforeRead ? chainChanges.at(-1) : chainId
|
|
47
|
+
});
|
|
48
|
+
} finally {
|
|
49
|
+
provider.removeListener("accountsChanged", handleAccountsChanged);
|
|
50
|
+
provider.removeListener("chainChanged", handleChainChanged);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
26
53
|
const getInjectedWalletAccounts$ = (wallet) => {
|
|
27
54
|
if (!wallet.isConnected) return (0, rxjs.of)([]);
|
|
28
55
|
return require_types.getCachedObservable$(`accounts:${wallet.id}`, () => new rxjs.Observable((subscriber) => {
|
|
29
56
|
const addresses$ = new rxjs.ReplaySubject(1);
|
|
30
57
|
const chainId$ = new rxjs.ReplaySubject(1);
|
|
58
|
+
const reported = lastReported.get(wallet.provider);
|
|
59
|
+
if (reported) {
|
|
60
|
+
addresses$.next(reported.addresses);
|
|
61
|
+
chainId$.next(reported.chainId);
|
|
62
|
+
}
|
|
31
63
|
const getAccount = (address, chainId) => {
|
|
32
64
|
const client = (0, viem.createWalletClient)({
|
|
33
65
|
account: address,
|
|
@@ -43,28 +75,47 @@ const getInjectedWalletAccounts$ = (wallet) => {
|
|
|
43
75
|
walletId: wallet.id
|
|
44
76
|
};
|
|
45
77
|
};
|
|
78
|
+
let accountEvents = 0;
|
|
79
|
+
let chainEvents = 0;
|
|
46
80
|
const handleAccountsChanged = (addrs) => {
|
|
81
|
+
accountEvents++;
|
|
47
82
|
addresses$.next(addrs);
|
|
48
83
|
};
|
|
49
84
|
const handleChainChanged = (chainIdHex) => {
|
|
85
|
+
chainEvents++;
|
|
50
86
|
chainId$.next(normalizeEvmChainId(chainIdHex));
|
|
51
87
|
};
|
|
52
88
|
const handleConnect = (connectInfo) => {
|
|
89
|
+
chainEvents++;
|
|
53
90
|
chainId$.next(normalizeEvmChainId(connectInfo?.chainId));
|
|
54
91
|
};
|
|
55
92
|
const handleDisconnect = () => {
|
|
93
|
+
chainEvents++;
|
|
56
94
|
chainId$.next(void 0);
|
|
57
95
|
};
|
|
58
96
|
wallet.provider.on("accountsChanged", handleAccountsChanged);
|
|
59
97
|
wallet.provider.on("chainChanged", handleChainChanged);
|
|
60
98
|
wallet.provider.on("connect", handleConnect);
|
|
61
99
|
wallet.provider.on("disconnect", handleDisconnect);
|
|
62
|
-
|
|
100
|
+
const accountEventsBeforeRead = accountEvents;
|
|
101
|
+
const accountsOutdated = () => accountEvents !== accountEventsBeforeRead;
|
|
102
|
+
wallet.provider.request({ method: "eth_accounts" }).then((addrs) => {
|
|
103
|
+
if (!accountsOutdated()) addresses$.next(addrs);
|
|
104
|
+
}).catch((err) => {
|
|
63
105
|
console.error("Failed to get accounts", err);
|
|
64
|
-
addresses$.next([]);
|
|
106
|
+
if (!accountsOutdated()) addresses$.next([]);
|
|
107
|
+
});
|
|
108
|
+
const chainEventsBeforeRead = chainEvents;
|
|
109
|
+
const chainOutdated = () => chainEvents !== chainEventsBeforeRead;
|
|
110
|
+
wallet.provider.request({ method: "eth_chainId" }).then((chainIdHex) => {
|
|
111
|
+
if (!chainOutdated()) chainId$.next(normalizeEvmChainId(chainIdHex));
|
|
112
|
+
}).catch(() => {
|
|
113
|
+
if (!chainOutdated()) chainId$.next(void 0);
|
|
65
114
|
});
|
|
66
|
-
|
|
67
|
-
|
|
115
|
+
const sub = (0, rxjs.combineLatest)([addresses$, chainId$]).pipe((0, rxjs.tap)(([addresses, chainId]) => lastReported.set(wallet.provider, {
|
|
116
|
+
addresses,
|
|
117
|
+
chainId
|
|
118
|
+
})), (0, rxjs.map)(([addresses, chainId]) => addresses.map((addr) => getAccount(addr, chainId)))).subscribe(subscriber);
|
|
68
119
|
return () => {
|
|
69
120
|
wallet.provider.removeListener("accountsChanged", handleAccountsChanged);
|
|
70
121
|
wallet.provider.removeListener("chainChanged", handleChainChanged);
|
|
@@ -188,9 +239,7 @@ const providersDetails$ = new rxjs.Observable((subscriber) => {
|
|
|
188
239
|
const getEthereumWallets$ = (store) => require_injectedWallets.createInjectedWallets$(store, {
|
|
189
240
|
sources$: providersDetails$,
|
|
190
241
|
getWalletId: (pd) => require_types.getWalletId("ethereum", pd.info.rdns),
|
|
191
|
-
connect:
|
|
192
|
-
await pd.provider.request({ method: "eth_requestAccounts" });
|
|
193
|
-
},
|
|
242
|
+
connect: (pd) => requestAccountsOnChain(pd.provider),
|
|
194
243
|
isUserRejection: require_errors.isEip1193UserRejection,
|
|
195
244
|
onDisconnected: (walletId) => require_types.clearCachedObservable(`accounts:${walletId}`),
|
|
196
245
|
buildWallet: ({ source: pd, walletId, status, error, isConnected, connect, disconnect }) => ({
|
package/dist/ethereum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethereum.js","names":["of","getCachedObservable$","Observable","ReplaySubject","createWalletClient","custom","getWalletAccountId","getAddress","combineLatest","map","shareReplay","getCaip10Addresses","getSessionCaip10s","distinctUntilChanged","createPlatformAccounts$","Observable","createMipdStore","shareReplay","createInjectedWallets$","getWalletId","isEip1193UserRejection","clearCachedObservable"],"sources":["../src/api/ethereum/accounts.ts","../src/api/ethereum/wallets.ts","../src/api/ethereum/plugin.ts"],"sourcesContent":["import {\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tof,\n\tReplaySubject,\n\tshareReplay,\n} from \"rxjs\";\nimport {\n\tcreateWalletClient,\n\tcustom,\n\ttype EIP1193Provider,\n\tgetAddress,\n} from \"viem\";\nimport { getWalletAccountId } from \"../../utils\";\nimport { getCachedObservable$ } from \"../../utils/getCachedObservable\";\nimport {\n\tcreatePlatformAccounts$,\n\tgetCaip10Addresses,\n\tgetSessionCaip10s,\n\ttype LiveWalletConnectWallet,\n} from \"../platformAccounts\";\nimport type { WalletConnectWallet } from \"../types\";\nimport type {\n\tEthereumAccount,\n\tEthereumInjectedWallet,\n\tEthereumWallet,\n} from \"./types\";\n\nconst normalizeEvmChainId = (value: unknown): number | undefined => {\n\tlet raw = value;\n\n\tif (typeof raw === \"string\" && raw.startsWith(\"eip155:\")) {\n\t\traw = raw.slice(\"eip155:\".length);\n\t}\n\n\tif (typeof raw === \"bigint\") {\n\t\treturn raw >= 0n ? Number(raw) : undefined;\n\t}\n\n\tif (typeof raw === \"number\") {\n\t\treturn Number.isInteger(raw) && raw >= 0 ? raw : undefined;\n\t}\n\n\tif (typeof raw === \"string\") {\n\t\tconst normalized = raw.trim().toLowerCase();\n\t\tif (!normalized) return undefined;\n\t\tconst parsed = normalized.startsWith(\"0x\")\n\t\t\t? Number.parseInt(normalized, 16)\n\t\t\t: Number.parseInt(normalized, 10);\n\t\treturn Number.isNaN(parsed) ? undefined : parsed;\n\t}\n\n\treturn undefined;\n};\n\nconst toCaipNetworkId = (value: unknown): string | undefined => {\n\tconst chainId = normalizeEvmChainId(value);\n\treturn chainId === undefined ? undefined : `eip155:${chainId}`;\n};\n\nconst getInjectedWalletAccounts$ = (\n\twallet: EthereumInjectedWallet,\n): Observable<EthereumAccount[]> => {\n\tif (!wallet.isConnected) return of([]);\n\n\treturn getCachedObservable$(`accounts:${wallet.id}`, () =>\n\t\tnew Observable<EthereumAccount[]>((subscriber) => {\n\t\t\tconst addresses$ = new ReplaySubject<string[]>(1);\n\t\t\tconst chainId$ = new ReplaySubject<number | undefined>(1);\n\n\t\t\tconst getAccount = (\n\t\t\t\taddress: string,\n\t\t\t\tchainId: number | undefined,\n\t\t\t): EthereumAccount => {\n\t\t\t\tconst client = createWalletClient({\n\t\t\t\t\taccount: address as `0x${string}`,\n\t\t\t\t\ttransport: custom(wallet.provider as EIP1193Provider),\n\t\t\t\t});\n\n\t\t\t\treturn {\n\t\t\t\t\tid: getWalletAccountId(wallet.id, address),\n\t\t\t\t\tplatform: \"ethereum\",\n\t\t\t\t\tclient,\n\t\t\t\t\taddress: getAddress(address),\n\t\t\t\t\tchainId,\n\t\t\t\t\twalletName: wallet.name,\n\t\t\t\t\twalletId: wallet.id,\n\t\t\t\t};\n\t\t\t};\n\n\t\t\tconst handleAccountsChanged = (addrs: string[]) => {\n\t\t\t\taddresses$.next(addrs);\n\t\t\t};\n\n\t\t\tconst handleChainChanged = (chainIdHex: unknown) => {\n\t\t\t\tchainId$.next(normalizeEvmChainId(chainIdHex));\n\t\t\t};\n\n\t\t\tconst handleConnect = (connectInfo: { chainId?: unknown }) => {\n\t\t\t\tchainId$.next(normalizeEvmChainId(connectInfo?.chainId));\n\t\t\t};\n\n\t\t\tconst handleDisconnect = () => {\n\t\t\t\tchainId$.next(undefined);\n\t\t\t};\n\n\t\t\t// Subscribe to provider events\n\t\t\twallet.provider.on(\"accountsChanged\", handleAccountsChanged);\n\t\t\twallet.provider.on(\"chainChanged\", handleChainChanged);\n\t\t\twallet.provider.on(\"connect\", handleConnect);\n\t\t\twallet.provider.on(\"disconnect\", handleDisconnect);\n\n\t\t\t// Fetch initial values\n\t\t\twallet.provider\n\t\t\t\t.request({ method: \"eth_accounts\" })\n\t\t\t\t.then((addrs: string[]) => addresses$.next(addrs))\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tconsole.error(\"Failed to get accounts\", err);\n\t\t\t\t\taddresses$.next([]);\n\t\t\t\t});\n\n\t\t\twallet.provider\n\t\t\t\t.request({ method: \"eth_chainId\" })\n\t\t\t\t.then(handleChainChanged)\n\t\t\t\t.catch(() => chainId$.next(undefined));\n\n\t\t\t// Combine addresses + chainId into account list\n\t\t\tconst sub = combineLatest([addresses$, chainId$])\n\t\t\t\t.pipe(\n\t\t\t\t\tmap(([addresses, chainId]) =>\n\t\t\t\t\t\taddresses.map((addr) => getAccount(addr, chainId)),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.subscribe(subscriber);\n\n\t\t\treturn () => {\n\t\t\t\twallet.provider.removeListener(\n\t\t\t\t\t\"accountsChanged\",\n\t\t\t\t\thandleAccountsChanged,\n\t\t\t\t);\n\t\t\t\twallet.provider.removeListener(\"chainChanged\", handleChainChanged);\n\t\t\t\twallet.provider.removeListener(\"connect\", handleConnect);\n\t\t\t\twallet.provider.removeListener(\"disconnect\", handleDisconnect);\n\t\t\t\tsub.unsubscribe();\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n\nconst wrapWalletConnectProvider = (\n\tprovider: EIP1193Provider,\n\tsessionTopic: string,\n\tcaipNetworkId: string | undefined,\n): EIP1193Provider => {\n\treturn new Proxy(provider, {\n\t\tget(target, prop, receiver) {\n\t\t\tif (prop !== \"request\") return Reflect.get(target, prop, receiver);\n\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: EIP-1193 request args\n\t\t\treturn (args: any) => {\n\t\t\t\tif (!args || typeof args !== \"object\" || !args.method)\n\t\t\t\t\treturn target.request(args);\n\t\t\t\t// Build a new object rather than mutating the caller's args: the\n\t\t\t\t// EIP-1193 request object is owned by viem and may be frozen or reused.\n\t\t\t\tconst next = { ...args };\n\t\t\t\tif (next.topic === undefined) next.topic = sessionTopic;\n\t\t\t\tif (next.chainId === undefined && caipNetworkId !== undefined)\n\t\t\t\t\tnext.chainId = caipNetworkId;\n\t\t\t\t// WalletConnect's UniversalProvider reads the target CAIP chain id from\n\t\t\t\t// the SECOND positional argument of `request(args, chainId)`, not from a\n\t\t\t\t// field on the args object. This AppKit instance has no native eip155\n\t\t\t\t// adapter, so the provider has no default chain — without the positional\n\t\t\t\t// chain id every call is rejected (\"Unsupported chains\" / \"Method not\n\t\t\t\t// found\"). Pass it positionally so the request routes to the session's\n\t\t\t\t// chain.\n\t\t\t\treturn (\n\t\t\t\t\ttarget.request as (a: unknown, chainId?: string) => Promise<unknown>\n\t\t\t\t)(next, caipNetworkId);\n\t\t\t};\n\t\t},\n\t});\n};\n\nconst sameAddresses = (a: string[], b: string[]) =>\n\ta.length === b.length && a.every((addr, i) => addr === b[i]);\n\nconst getWalletConnectAccounts$ = (\n\twallet: LiveWalletConnectWallet,\n): Observable<EthereumAccount[]> => {\n\tconst provider = wallet.appKit.getProvider(\"eip155\");\n\n\tif (!wallet.platforms.includes(\"ethereum\") || !provider?.session)\n\t\treturn of([]);\n\n\treturn getCachedObservable$(`accounts:${wallet.id}:ethereum:`, () =>\n\t\tnew Observable<EthereumAccount[]>((subscriber) => {\n\t\t\tconst caipNetworkId$ = new ReplaySubject<string | undefined>(1);\n\t\t\tconst addresses$ = new ReplaySubject<string[]>(1);\n\n\t\t\t// AppKit's getAccount(\"eip155\").allAccounts is empty because this AppKit\n\t\t\t// instance has no native eip155 adapter — eip155 runs through the\n\t\t\t// WalletConnect UniversalProvider, so the session is the source of truth\n\t\t\t// (mirrors the polkadot/solana AppKit paths). Accounts are CAIP-10 strings\n\t\t\t// (\"eip155:<chainRef>:<address>\"), one entry per chain, so dedupe to unique\n\t\t\t// addresses. Read live on each change so switching/adding accounts is\n\t\t\t// reflected.\n\t\t\tconst readAddresses = (): string[] => {\n\t\t\t\tconst session = provider.session;\n\t\t\t\tif (!session) return [];\n\t\t\t\tconst addresses = new Set<string>();\n\t\t\t\tfor (const raw of getCaip10Addresses(\n\t\t\t\t\tgetSessionCaip10s(session, \"eip155\"),\n\t\t\t\t)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\taddresses.add(getAddress(raw));\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// skip malformed CAIP-10 address\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn [...addresses];\n\t\t\t};\n\n\t\t\t// Derive the CAIP network id from the session's eip155 CAIP-10 accounts\n\t\t\t// (\"eip155:<ref>:<addr>\") as a synchronous fallback for eth_chainId.\n\t\t\tconst readCaipNetworkId = (): string | undefined => {\n\t\t\t\tconst session = provider.session;\n\t\t\t\tif (!session) return undefined;\n\t\t\t\tfor (const account of getSessionCaip10s(session, \"eip155\")) {\n\t\t\t\t\tconst ref = account.split(\":\")[1];\n\t\t\t\t\tif (ref) return `eip155:${ref}`;\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t};\n\n\t\t\tconst handleChainChanged = (chainId: unknown) => {\n\t\t\t\tconst caipNetworkId = toCaipNetworkId(chainId);\n\t\t\t\tif (caipNetworkId) {\n\t\t\t\t\tcaipNetworkId$.next(caipNetworkId);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst handleAccountsChanged = () => addresses$.next(readAddresses());\n\n\t\t\tprovider.on(\"chainChanged\", handleChainChanged);\n\t\t\tprovider.on(\"accountsChanged\", handleAccountsChanged);\n\t\t\tprovider.on(\"session_update\", handleAccountsChanged);\n\t\t\t// Seed the chain id from the session synchronously so the account list can\n\t\t\t// surface even if eth_chainId never resolves; eth_chainId then refines it.\n\t\t\t// Without this seed, combineLatest below never fires when eth_chainId\n\t\t\t// rejects or returns an unparseable value, and the accounts silently never\n\t\t\t// appear (the injected path seeds undefined on failure for the same reason).\n\t\t\tcaipNetworkId$.next(readCaipNetworkId());\n\t\t\tprovider\n\t\t\t\t.request({ method: \"eth_chainId\" })\n\t\t\t\t.then(handleChainChanged)\n\t\t\t\t.catch(() => {});\n\t\t\taddresses$.next(readAddresses());\n\n\t\t\tconst sub = combineLatest([\n\t\t\t\tcaipNetworkId$.pipe(distinctUntilChanged()),\n\t\t\t\taddresses$.pipe(distinctUntilChanged(sameAddresses)),\n\t\t\t])\n\t\t\t\t.pipe(\n\t\t\t\t\tmap(([caipNetworkId, addresses]) => {\n\t\t\t\t\t\tconst chainId = normalizeEvmChainId(caipNetworkId);\n\t\t\t\t\t\tconst transport = custom(\n\t\t\t\t\t\t\twrapWalletConnectProvider(\n\t\t\t\t\t\t\t\tprovider as unknown as EIP1193Provider,\n\t\t\t\t\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: legacy\n\t\t\t\t\t\t\t\tprovider.session!.topic,\n\t\t\t\t\t\t\t\tcaipNetworkId,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn addresses.map((addr): EthereumAccount => {\n\t\t\t\t\t\t\tconst client = createWalletClient({\n\t\t\t\t\t\t\t\taccount: addr as `0x${string}`,\n\t\t\t\t\t\t\t\ttransport,\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tid: getWalletAccountId(wallet.id, addr),\n\t\t\t\t\t\t\t\tplatform: \"ethereum\",\n\t\t\t\t\t\t\t\twalletName: wallet.name,\n\t\t\t\t\t\t\t\twalletId: wallet.id,\n\t\t\t\t\t\t\t\taddress: addr as `0x${string}`,\n\t\t\t\t\t\t\t\tclient,\n\t\t\t\t\t\t\t\tchainId,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t});\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.subscribe(subscriber);\n\n\t\t\treturn () => {\n\t\t\t\tprovider.off(\"chainChanged\", handleChainChanged);\n\t\t\t\tprovider.off(\"accountsChanged\", handleAccountsChanged);\n\t\t\t\tprovider.off(\"session_update\", handleAccountsChanged);\n\t\t\t\tsub.unsubscribe();\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n\nexport const getEthereumAccounts$ = (\n\tethereumWallets: Observable<(EthereumWallet | WalletConnectWallet)[]>,\n) =>\n\tcreatePlatformAccounts$({\n\t\twallets$: ethereumWallets,\n\t\tgetInjectedAccounts$: getInjectedWalletAccounts$,\n\t\tgetWalletConnectAccounts$,\n\t\t// Re-emit on chain switches, not just account id changes.\n\t\taccountChangeKey: (account) => `${account.id}|${account.chainId ?? \"\"}`,\n\t});\n","import {\n\tcreateStore as createMipdStore,\n\ttype EIP6963ProviderDetail,\n} from \"mipd\";\nimport { Observable, shareReplay } from \"rxjs\";\nimport type { EIP1193Provider } from \"viem\";\nimport { clearCachedObservable } from \"../../utils/getCachedObservable\";\nimport { getWalletId } from \"../../utils/WalletId\";\nimport { isEip1193UserRejection } from \"../errors\";\nimport { createInjectedWallets$ } from \"../injectedWallets\";\nimport type { KheopskitStore } from \"../store\";\nimport type { EthereumInjectedWallet } from \"./types\";\n\n/**\n * Observable that emits EIP-6963 provider details from injected wallets.\n * Returns empty array during SSR since browser wallet APIs are not available.\n */\nconst providersDetails$ = new Observable<EIP6963ProviderDetail[]>(\n\t(subscriber) => {\n\t\t// Guard against SSR - mipd requires browser APIs\n\t\tif (typeof window === \"undefined\") {\n\t\t\tsubscriber.next([]);\n\t\t\treturn () => {};\n\t\t}\n\n\t\tconst mipdStore = createMipdStore();\n\n\t\tconst unsubscribe = mipdStore.subscribe((providerDetails) => {\n\t\t\tsubscriber.next(providerDetails as EIP6963ProviderDetail[]);\n\t\t});\n\n\t\tconst providerDetails = mipdStore.getProviders();\n\n\t\tsubscriber.next(providerDetails as EIP6963ProviderDetail[]);\n\n\t\treturn () => {\n\t\t\tunsubscribe();\n\t\t\tmipdStore.destroy();\n\t\t};\n\t},\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\n// The shared WalletConnect connector is emitted once by core (see\n// `getWallets$`), not per platform — so this returns only injected wallets.\nexport const getEthereumWallets$ = (store: KheopskitStore) =>\n\tcreateInjectedWallets$<EIP6963ProviderDetail, EthereumInjectedWallet>(store, {\n\t\tsources$: providersDetails$,\n\t\tgetWalletId: (pd) => getWalletId(\"ethereum\", pd.info.rdns),\n\t\tconnect: async (pd) => {\n\t\t\tawait (pd.provider as EIP1193Provider).request({\n\t\t\t\tmethod: \"eth_requestAccounts\",\n\t\t\t});\n\t\t},\n\t\tisUserRejection: isEip1193UserRejection,\n\t\t// Drop the cached account observable so a later reconnect rebuilds it\n\t\t// against the current provider, not a stale closure.\n\t\tonDisconnected: (walletId) => clearCachedObservable(`accounts:${walletId}`),\n\t\tbuildWallet: ({\n\t\t\tsource: pd,\n\t\t\twalletId,\n\t\t\tstatus,\n\t\t\terror,\n\t\t\tisConnected,\n\t\t\tconnect,\n\t\t\tdisconnect,\n\t\t}) => ({\n\t\t\tplatform: \"ethereum\",\n\t\t\ttype: \"injected\",\n\t\t\tid: walletId,\n\t\t\tname: pd.info.name,\n\t\t\ticon: pd.info.icon,\n\t\t\tprovider: pd.provider as EIP1193Provider,\n\t\t\tstatus,\n\t\t\terror,\n\t\t\tisConnected,\n\t\t\tsourceId: pd.info.rdns,\n\t\t\tconnect,\n\t\t\tdisconnect,\n\t\t}),\n\t});\n","import type { KheopskitPlatform, PlatformContext } from \"../types\";\nimport { getEthereumAccounts$ } from \"./accounts\";\nimport type { EthereumAccount, EthereumWallet } from \"./types\";\nimport { getEthereumWallets$ } from \"./wallets\";\n\n/**\n * Ethereum platform plugin. Pass to `createKheopskit({ platforms: [ethereum()] })`.\n *\n * @example\n * ```ts\n * import { ethereum } from \"@kheopskit/core/ethereum\";\n * ethereum();\n * ```\n */\nexport const ethereum = (): KheopskitPlatform<\n\t\"ethereum\",\n\tEthereumWallet,\n\tEthereumAccount\n> => ({\n\tplatform: \"ethereum\",\n\tgetWallets$: (ctx: PlatformContext) => getEthereumWallets$(ctx.store),\n\tgetAccounts$: (wallets$) => getEthereumAccounts$(wallets$),\n});\n"],"mappings":";;;;;;;;;AA8BA,MAAM,uBAAuB,UAAuC;CACnE,IAAI,MAAM;CAEV,IAAI,OAAO,QAAQ,YAAY,IAAI,WAAW,SAAS,GACtD,MAAM,IAAI,MAAM,CAAgB;CAGjC,IAAI,OAAO,QAAQ,UAClB,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AM;EACN,IAAI;EACJ,MAAM,GAAG,KAAK;EACd,MAAM,GAAG,KAAK;EACd,UAAU,GAAG;EACb;EACA;EACA;EACA,UAAU,GAAG,KAAK;EAClB;EACA;CACD;AACD,CAAC;;;;;;;;;;;;ACjEF,MAAa,kBAIP;CACL,UAAU;CACV,cAAc,QAAyB,oBAAoB,IAAI,KAAK;CACpE,eAAe,aAAa,qBAAqB,QAAQ;AAC1D"}
|
|
1
|
+
{"version":3,"file":"ethereum.js","names":["firstValueFrom","race","timer","map","of","getCachedObservable$","Observable","ReplaySubject","createWalletClient","custom","getWalletAccountId","getAddress","combineLatest","tap","shareReplay","getCaip10Addresses","getSessionCaip10s","distinctUntilChanged","createPlatformAccounts$","Observable","createMipdStore","shareReplay","createInjectedWallets$","getWalletId","isEip1193UserRejection","clearCachedObservable"],"sources":["../src/api/ethereum/accounts.ts","../src/api/ethereum/wallets.ts","../src/api/ethereum/plugin.ts"],"sourcesContent":["import {\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tfirstValueFrom,\n\tmap,\n\tObservable,\n\tof,\n\tReplaySubject,\n\trace,\n\tshareReplay,\n\ttap,\n\ttimer,\n} from \"rxjs\";\nimport {\n\tcreateWalletClient,\n\tcustom,\n\ttype EIP1193Provider,\n\tgetAddress,\n} from \"viem\";\nimport { getWalletAccountId } from \"../../utils\";\nimport { getCachedObservable$ } from \"../../utils/getCachedObservable\";\nimport {\n\tcreatePlatformAccounts$,\n\tgetCaip10Addresses,\n\tgetSessionCaip10s,\n\ttype LiveWalletConnectWallet,\n} from \"../platformAccounts\";\nimport type { WalletConnectWallet } from \"../types\";\nimport type {\n\tEthereumAccount,\n\tEthereumInjectedWallet,\n\tEthereumWallet,\n} from \"./types\";\n\nconst normalizeEvmChainId = (value: unknown): number | undefined => {\n\tlet raw = value;\n\n\tif (typeof raw === \"string\" && raw.startsWith(\"eip155:\")) {\n\t\traw = raw.slice(\"eip155:\".length);\n\t}\n\n\tif (typeof raw === \"bigint\") {\n\t\treturn raw >= 0n ? Number(raw) : undefined;\n\t}\n\n\tif (typeof raw === \"number\") {\n\t\treturn Number.isInteger(raw) && raw >= 0 ? raw : undefined;\n\t}\n\n\tif (typeof raw === \"string\") {\n\t\tconst normalized = raw.trim().toLowerCase();\n\t\tif (!normalized) return undefined;\n\t\tconst parsed = normalized.startsWith(\"0x\")\n\t\t\t? Number.parseInt(normalized, 16)\n\t\t\t: Number.parseInt(normalized, 10);\n\t\treturn Number.isNaN(parsed) ? undefined : parsed;\n\t}\n\n\treturn undefined;\n};\n\nconst toCaipNetworkId = (value: unknown): string | undefined => {\n\tconst chainId = normalizeEvmChainId(value);\n\treturn chainId === undefined ? undefined : `eip155:${chainId}`;\n};\n\ntype ReportedAccounts = { addresses: string[]; chainId: number | undefined };\n\nconst lastReported = new WeakMap<EIP1193Provider, ReportedAccounts>();\n\nconst CHAIN_ANSWER_TIMEOUT_MS = 2_000;\n\nconst readChainId = (provider: EIP1193Provider) =>\n\tfirstValueFrom(\n\t\trace(\n\t\t\tprovider\n\t\t\t\t.request({ method: \"eth_chainId\" })\n\t\t\t\t.then(normalizeEvmChainId, () => undefined),\n\t\t\ttimer(CHAIN_ANSWER_TIMEOUT_MS).pipe(map(() => undefined)),\n\t\t),\n\t);\n\nexport const requestAccountsOnChain = async (provider: EIP1193Provider) => {\n\tconst accountChanges: string[][] = [];\n\tconst chainChanges: (number | undefined)[] = [];\n\tconst handleAccountsChanged = (addresses: string[]) => {\n\t\taccountChanges.push(addresses);\n\t};\n\tconst handleChainChanged = (chainId: unknown) => {\n\t\tchainChanges.push(normalizeEvmChainId(chainId));\n\t};\n\tprovider.on(\"accountsChanged\", handleAccountsChanged);\n\tprovider.on(\"chainChanged\", handleChainChanged);\n\ttry {\n\t\tconst addresses = await provider.request({\n\t\t\tmethod: \"eth_requestAccounts\",\n\t\t});\n\t\tconst chainChangesBeforeRead = chainChanges.length;\n\t\tconst chainId = await readChainId(provider);\n\t\tlastReported.set(provider, {\n\t\t\taddresses: accountChanges.at(-1) ?? addresses,\n\t\t\tchainId:\n\t\t\t\tchainChanges.length > chainChangesBeforeRead\n\t\t\t\t\t? chainChanges.at(-1)\n\t\t\t\t\t: chainId,\n\t\t});\n\t} finally {\n\t\tprovider.removeListener(\"accountsChanged\", handleAccountsChanged);\n\t\tprovider.removeListener(\"chainChanged\", handleChainChanged);\n\t}\n};\n\nconst getInjectedWalletAccounts$ = (\n\twallet: EthereumInjectedWallet,\n): Observable<EthereumAccount[]> => {\n\tif (!wallet.isConnected) return of([]);\n\n\treturn getCachedObservable$(`accounts:${wallet.id}`, () =>\n\t\tnew Observable<EthereumAccount[]>((subscriber) => {\n\t\t\tconst addresses$ = new ReplaySubject<string[]>(1);\n\t\t\tconst chainId$ = new ReplaySubject<number | undefined>(1);\n\t\t\tconst reported = lastReported.get(wallet.provider);\n\t\t\tif (reported) {\n\t\t\t\taddresses$.next(reported.addresses);\n\t\t\t\tchainId$.next(reported.chainId);\n\t\t\t}\n\n\t\t\tconst getAccount = (\n\t\t\t\taddress: string,\n\t\t\t\tchainId: number | undefined,\n\t\t\t): EthereumAccount => {\n\t\t\t\tconst client = createWalletClient({\n\t\t\t\t\taccount: address as `0x${string}`,\n\t\t\t\t\ttransport: custom(wallet.provider as EIP1193Provider),\n\t\t\t\t});\n\n\t\t\t\treturn {\n\t\t\t\t\tid: getWalletAccountId(wallet.id, address),\n\t\t\t\t\tplatform: \"ethereum\",\n\t\t\t\t\tclient,\n\t\t\t\t\taddress: getAddress(address),\n\t\t\t\t\tchainId,\n\t\t\t\t\twalletName: wallet.name,\n\t\t\t\t\twalletId: wallet.id,\n\t\t\t\t};\n\t\t\t};\n\n\t\t\tlet accountEvents = 0;\n\t\t\tlet chainEvents = 0;\n\n\t\t\tconst handleAccountsChanged = (addrs: string[]) => {\n\t\t\t\taccountEvents++;\n\t\t\t\taddresses$.next(addrs);\n\t\t\t};\n\n\t\t\tconst handleChainChanged = (chainIdHex: unknown) => {\n\t\t\t\tchainEvents++;\n\t\t\t\tchainId$.next(normalizeEvmChainId(chainIdHex));\n\t\t\t};\n\n\t\t\tconst handleConnect = (connectInfo: { chainId?: unknown }) => {\n\t\t\t\tchainEvents++;\n\t\t\t\tchainId$.next(normalizeEvmChainId(connectInfo?.chainId));\n\t\t\t};\n\n\t\t\tconst handleDisconnect = () => {\n\t\t\t\tchainEvents++;\n\t\t\t\tchainId$.next(undefined);\n\t\t\t};\n\n\t\t\t// Subscribe to provider events\n\t\t\twallet.provider.on(\"accountsChanged\", handleAccountsChanged);\n\t\t\twallet.provider.on(\"chainChanged\", handleChainChanged);\n\t\t\twallet.provider.on(\"connect\", handleConnect);\n\t\t\twallet.provider.on(\"disconnect\", handleDisconnect);\n\n\t\t\tconst accountEventsBeforeRead = accountEvents;\n\t\t\tconst accountsOutdated = () => accountEvents !== accountEventsBeforeRead;\n\t\t\twallet.provider\n\t\t\t\t.request({ method: \"eth_accounts\" })\n\t\t\t\t.then((addrs: string[]) => {\n\t\t\t\t\tif (!accountsOutdated()) addresses$.next(addrs);\n\t\t\t\t})\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tconsole.error(\"Failed to get accounts\", err);\n\t\t\t\t\tif (!accountsOutdated()) addresses$.next([]);\n\t\t\t\t});\n\n\t\t\tconst chainEventsBeforeRead = chainEvents;\n\t\t\tconst chainOutdated = () => chainEvents !== chainEventsBeforeRead;\n\t\t\twallet.provider\n\t\t\t\t.request({ method: \"eth_chainId\" })\n\t\t\t\t.then((chainIdHex: unknown) => {\n\t\t\t\t\tif (!chainOutdated()) chainId$.next(normalizeEvmChainId(chainIdHex));\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\tif (!chainOutdated()) chainId$.next(undefined);\n\t\t\t\t});\n\n\t\t\t// Combine addresses + chainId into account list\n\t\t\tconst sub = combineLatest([addresses$, chainId$])\n\t\t\t\t.pipe(\n\t\t\t\t\ttap(([addresses, chainId]) =>\n\t\t\t\t\t\tlastReported.set(wallet.provider, { addresses, chainId }),\n\t\t\t\t\t),\n\t\t\t\t\tmap(([addresses, chainId]) =>\n\t\t\t\t\t\taddresses.map((addr) => getAccount(addr, chainId)),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.subscribe(subscriber);\n\n\t\t\treturn () => {\n\t\t\t\twallet.provider.removeListener(\n\t\t\t\t\t\"accountsChanged\",\n\t\t\t\t\thandleAccountsChanged,\n\t\t\t\t);\n\t\t\t\twallet.provider.removeListener(\"chainChanged\", handleChainChanged);\n\t\t\t\twallet.provider.removeListener(\"connect\", handleConnect);\n\t\t\t\twallet.provider.removeListener(\"disconnect\", handleDisconnect);\n\t\t\t\tsub.unsubscribe();\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n\nconst wrapWalletConnectProvider = (\n\tprovider: EIP1193Provider,\n\tsessionTopic: string,\n\tcaipNetworkId: string | undefined,\n): EIP1193Provider => {\n\treturn new Proxy(provider, {\n\t\tget(target, prop, receiver) {\n\t\t\tif (prop !== \"request\") return Reflect.get(target, prop, receiver);\n\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: EIP-1193 request args\n\t\t\treturn (args: any) => {\n\t\t\t\tif (!args || typeof args !== \"object\" || !args.method)\n\t\t\t\t\treturn target.request(args);\n\t\t\t\t// Build a new object rather than mutating the caller's args: the\n\t\t\t\t// EIP-1193 request object is owned by viem and may be frozen or reused.\n\t\t\t\tconst next = { ...args };\n\t\t\t\tif (next.topic === undefined) next.topic = sessionTopic;\n\t\t\t\tif (next.chainId === undefined && caipNetworkId !== undefined)\n\t\t\t\t\tnext.chainId = caipNetworkId;\n\t\t\t\t// WalletConnect's UniversalProvider reads the target CAIP chain id from\n\t\t\t\t// the SECOND positional argument of `request(args, chainId)`, not from a\n\t\t\t\t// field on the args object. This AppKit instance has no native eip155\n\t\t\t\t// adapter, so the provider has no default chain — without the positional\n\t\t\t\t// chain id every call is rejected (\"Unsupported chains\" / \"Method not\n\t\t\t\t// found\"). Pass it positionally so the request routes to the session's\n\t\t\t\t// chain.\n\t\t\t\treturn (\n\t\t\t\t\ttarget.request as (a: unknown, chainId?: string) => Promise<unknown>\n\t\t\t\t)(next, caipNetworkId);\n\t\t\t};\n\t\t},\n\t});\n};\n\nconst sameAddresses = (a: string[], b: string[]) =>\n\ta.length === b.length && a.every((addr, i) => addr === b[i]);\n\nconst getWalletConnectAccounts$ = (\n\twallet: LiveWalletConnectWallet,\n): Observable<EthereumAccount[]> => {\n\tconst provider = wallet.appKit.getProvider(\"eip155\");\n\n\tif (!wallet.platforms.includes(\"ethereum\") || !provider?.session)\n\t\treturn of([]);\n\n\treturn getCachedObservable$(`accounts:${wallet.id}:ethereum:`, () =>\n\t\tnew Observable<EthereumAccount[]>((subscriber) => {\n\t\t\tconst caipNetworkId$ = new ReplaySubject<string | undefined>(1);\n\t\t\tconst addresses$ = new ReplaySubject<string[]>(1);\n\n\t\t\t// AppKit's getAccount(\"eip155\").allAccounts is empty because this AppKit\n\t\t\t// instance has no native eip155 adapter — eip155 runs through the\n\t\t\t// WalletConnect UniversalProvider, so the session is the source of truth\n\t\t\t// (mirrors the polkadot/solana AppKit paths). Accounts are CAIP-10 strings\n\t\t\t// (\"eip155:<chainRef>:<address>\"), one entry per chain, so dedupe to unique\n\t\t\t// addresses. Read live on each change so switching/adding accounts is\n\t\t\t// reflected.\n\t\t\tconst readAddresses = (): string[] => {\n\t\t\t\tconst session = provider.session;\n\t\t\t\tif (!session) return [];\n\t\t\t\tconst addresses = new Set<string>();\n\t\t\t\tfor (const raw of getCaip10Addresses(\n\t\t\t\t\tgetSessionCaip10s(session, \"eip155\"),\n\t\t\t\t)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\taddresses.add(getAddress(raw));\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// skip malformed CAIP-10 address\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn [...addresses];\n\t\t\t};\n\n\t\t\t// Derive the CAIP network id from the session's eip155 CAIP-10 accounts\n\t\t\t// (\"eip155:<ref>:<addr>\") as a synchronous fallback for eth_chainId.\n\t\t\tconst readCaipNetworkId = (): string | undefined => {\n\t\t\t\tconst session = provider.session;\n\t\t\t\tif (!session) return undefined;\n\t\t\t\tfor (const account of getSessionCaip10s(session, \"eip155\")) {\n\t\t\t\t\tconst ref = account.split(\":\")[1];\n\t\t\t\t\tif (ref) return `eip155:${ref}`;\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t};\n\n\t\t\tconst handleChainChanged = (chainId: unknown) => {\n\t\t\t\tconst caipNetworkId = toCaipNetworkId(chainId);\n\t\t\t\tif (caipNetworkId) {\n\t\t\t\t\tcaipNetworkId$.next(caipNetworkId);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst handleAccountsChanged = () => addresses$.next(readAddresses());\n\n\t\t\tprovider.on(\"chainChanged\", handleChainChanged);\n\t\t\tprovider.on(\"accountsChanged\", handleAccountsChanged);\n\t\t\tprovider.on(\"session_update\", handleAccountsChanged);\n\t\t\t// Seed the chain id from the session synchronously so the account list can\n\t\t\t// surface even if eth_chainId never resolves; eth_chainId then refines it.\n\t\t\t// Without this seed, combineLatest below never fires when eth_chainId\n\t\t\t// rejects or returns an unparseable value, and the accounts silently never\n\t\t\t// appear (the injected path seeds undefined on failure for the same reason).\n\t\t\tcaipNetworkId$.next(readCaipNetworkId());\n\t\t\tprovider\n\t\t\t\t.request({ method: \"eth_chainId\" })\n\t\t\t\t.then(handleChainChanged)\n\t\t\t\t.catch(() => {});\n\t\t\taddresses$.next(readAddresses());\n\n\t\t\tconst sub = combineLatest([\n\t\t\t\tcaipNetworkId$.pipe(distinctUntilChanged()),\n\t\t\t\taddresses$.pipe(distinctUntilChanged(sameAddresses)),\n\t\t\t])\n\t\t\t\t.pipe(\n\t\t\t\t\tmap(([caipNetworkId, addresses]) => {\n\t\t\t\t\t\tconst chainId = normalizeEvmChainId(caipNetworkId);\n\t\t\t\t\t\tconst transport = custom(\n\t\t\t\t\t\t\twrapWalletConnectProvider(\n\t\t\t\t\t\t\t\tprovider as unknown as EIP1193Provider,\n\t\t\t\t\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: legacy\n\t\t\t\t\t\t\t\tprovider.session!.topic,\n\t\t\t\t\t\t\t\tcaipNetworkId,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn addresses.map((addr): EthereumAccount => {\n\t\t\t\t\t\t\tconst client = createWalletClient({\n\t\t\t\t\t\t\t\taccount: addr as `0x${string}`,\n\t\t\t\t\t\t\t\ttransport,\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tid: getWalletAccountId(wallet.id, addr),\n\t\t\t\t\t\t\t\tplatform: \"ethereum\",\n\t\t\t\t\t\t\t\twalletName: wallet.name,\n\t\t\t\t\t\t\t\twalletId: wallet.id,\n\t\t\t\t\t\t\t\taddress: addr as `0x${string}`,\n\t\t\t\t\t\t\t\tclient,\n\t\t\t\t\t\t\t\tchainId,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t});\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.subscribe(subscriber);\n\n\t\t\treturn () => {\n\t\t\t\tprovider.off(\"chainChanged\", handleChainChanged);\n\t\t\t\tprovider.off(\"accountsChanged\", handleAccountsChanged);\n\t\t\t\tprovider.off(\"session_update\", handleAccountsChanged);\n\t\t\t\tsub.unsubscribe();\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n\nexport const getEthereumAccounts$ = (\n\tethereumWallets: Observable<(EthereumWallet | WalletConnectWallet)[]>,\n) =>\n\tcreatePlatformAccounts$({\n\t\twallets$: ethereumWallets,\n\t\tgetInjectedAccounts$: getInjectedWalletAccounts$,\n\t\tgetWalletConnectAccounts$,\n\t\t// Re-emit on chain switches, not just account id changes.\n\t\taccountChangeKey: (account) => `${account.id}|${account.chainId ?? \"\"}`,\n\t});\n","import {\n\tcreateStore as createMipdStore,\n\ttype EIP6963ProviderDetail,\n} from \"mipd\";\nimport { Observable, shareReplay } from \"rxjs\";\nimport type { EIP1193Provider } from \"viem\";\nimport { clearCachedObservable } from \"../../utils/getCachedObservable\";\nimport { getWalletId } from \"../../utils/WalletId\";\nimport { isEip1193UserRejection } from \"../errors\";\nimport { createInjectedWallets$ } from \"../injectedWallets\";\nimport type { KheopskitStore } from \"../store\";\nimport { requestAccountsOnChain } from \"./accounts\";\nimport type { EthereumInjectedWallet } from \"./types\";\n\n/**\n * Observable that emits EIP-6963 provider details from injected wallets.\n * Returns empty array during SSR since browser wallet APIs are not available.\n */\nconst providersDetails$ = new Observable<EIP6963ProviderDetail[]>(\n\t(subscriber) => {\n\t\t// Guard against SSR - mipd requires browser APIs\n\t\tif (typeof window === \"undefined\") {\n\t\t\tsubscriber.next([]);\n\t\t\treturn () => {};\n\t\t}\n\n\t\tconst mipdStore = createMipdStore();\n\n\t\tconst unsubscribe = mipdStore.subscribe((providerDetails) => {\n\t\t\tsubscriber.next(providerDetails as EIP6963ProviderDetail[]);\n\t\t});\n\n\t\tconst providerDetails = mipdStore.getProviders();\n\n\t\tsubscriber.next(providerDetails as EIP6963ProviderDetail[]);\n\n\t\treturn () => {\n\t\t\tunsubscribe();\n\t\t\tmipdStore.destroy();\n\t\t};\n\t},\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\n// The shared WalletConnect connector is emitted once by core (see\n// `getWallets$`), not per platform — so this returns only injected wallets.\nexport const getEthereumWallets$ = (store: KheopskitStore) =>\n\tcreateInjectedWallets$<EIP6963ProviderDetail, EthereumInjectedWallet>(store, {\n\t\tsources$: providersDetails$,\n\t\tgetWalletId: (pd) => getWalletId(\"ethereum\", pd.info.rdns),\n\t\tconnect: (pd) => requestAccountsOnChain(pd.provider as EIP1193Provider),\n\t\tisUserRejection: isEip1193UserRejection,\n\t\t// Drop the cached account observable so a later reconnect rebuilds it\n\t\t// against the current provider, not a stale closure.\n\t\tonDisconnected: (walletId) => clearCachedObservable(`accounts:${walletId}`),\n\t\tbuildWallet: ({\n\t\t\tsource: pd,\n\t\t\twalletId,\n\t\t\tstatus,\n\t\t\terror,\n\t\t\tisConnected,\n\t\t\tconnect,\n\t\t\tdisconnect,\n\t\t}) => ({\n\t\t\tplatform: \"ethereum\",\n\t\t\ttype: \"injected\",\n\t\t\tid: walletId,\n\t\t\tname: pd.info.name,\n\t\t\ticon: pd.info.icon,\n\t\t\tprovider: pd.provider as EIP1193Provider,\n\t\t\tstatus,\n\t\t\terror,\n\t\t\tisConnected,\n\t\t\tsourceId: pd.info.rdns,\n\t\t\tconnect,\n\t\t\tdisconnect,\n\t\t}),\n\t});\n","import type { KheopskitPlatform, PlatformContext } from \"../types\";\nimport { getEthereumAccounts$ } from \"./accounts\";\nimport type { EthereumAccount, EthereumWallet } from \"./types\";\nimport { getEthereumWallets$ } from \"./wallets\";\n\n/**\n * Ethereum platform plugin. Pass to `createKheopskit({ platforms: [ethereum()] })`.\n *\n * @example\n * ```ts\n * import { ethereum } from \"@kheopskit/core/ethereum\";\n * ethereum();\n * ```\n */\nexport const ethereum = (): KheopskitPlatform<\n\t\"ethereum\",\n\tEthereumWallet,\n\tEthereumAccount\n> => ({\n\tplatform: \"ethereum\",\n\tgetWallets$: (ctx: PlatformContext) => getEthereumWallets$(ctx.store),\n\tgetAccounts$: (wallets$) => getEthereumAccounts$(wallets$),\n});\n"],"mappings":";;;;;;;;;AAkCA,MAAM,uBAAuB,UAAuC;CACnE,IAAI,MAAM;CAEV,IAAI,OAAO,QAAQ,YAAY,IAAI,WAAW,SAAS,GACtD,MAAM,IAAI,MAAM,CAAgB;CAGjC,IAAI,OAAO,QAAQ,UAClB,OAAO,OAAO,KAAK,OAAO,GAAG,IAAI,KAAA;CAGlC,IAAI,OAAO,QAAQ,UAClB,OAAO,OAAO,UAAU,GAAG,KAAK,OAAO,IAAI,MAAM,KAAA;CAGlD,IAAI,OAAO,QAAQ,UAAU;EAC5B,MAAM,aAA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;CAC1E,cAAc,EACb,QAAQ,IACR,UACA,QACA,OACA,aACA,SACA,kBACM;EACN,UAAU;EACV,MAAM;EACN,IAAI;EACJ,MAAM,GAAG,KAAK;EACd,MAAM,GAAG,KAAK;EACd,UAAU,GAAG;EACb;EACA;EACA;EACA,UAAU,GAAG,KAAK;EAClB;EACA;CACD;AACD,CAAC;;;;;;;;;;;;AC9DF,MAAa,kBAIP;CACL,UAAU;CACV,cAAc,QAAyB,oBAAoB,IAAI,KAAK;CACpE,eAAe,aAAa,qBAAqB,QAAQ;AAC1D"}
|
package/dist/ethereum.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { d as getCachedObservable$, i as getWalletId, l as clearCachedObservable
|
|
|
2
2
|
import { d as isEthereumAddress, i as getSessionCaip10s, o as getWalletAccountId, r as getCaip10Addresses, t as createPlatformAccounts$ } from "./platformAccounts-C1sFv82e.mjs";
|
|
3
3
|
import { i as isEip1193UserRejection } from "./errors-DszTFbnO.mjs";
|
|
4
4
|
import { t as createInjectedWallets$ } from "./injectedWallets-CUo7rVqB.mjs";
|
|
5
|
-
import { Observable, ReplaySubject, combineLatest, distinctUntilChanged, map, of, shareReplay } from "rxjs";
|
|
5
|
+
import { Observable, ReplaySubject, combineLatest, distinctUntilChanged, firstValueFrom, map, of, race, shareReplay, tap, timer } from "rxjs";
|
|
6
6
|
import { createWalletClient, custom, getAddress } from "viem";
|
|
7
7
|
import { createStore } from "mipd";
|
|
8
8
|
//#region src/api/ethereum/accounts.ts
|
|
@@ -22,11 +22,43 @@ const toCaipNetworkId = (value) => {
|
|
|
22
22
|
const chainId = normalizeEvmChainId(value);
|
|
23
23
|
return chainId === void 0 ? void 0 : `eip155:${chainId}`;
|
|
24
24
|
};
|
|
25
|
+
const lastReported = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
const CHAIN_ANSWER_TIMEOUT_MS = 2e3;
|
|
27
|
+
const readChainId = (provider) => firstValueFrom(race(provider.request({ method: "eth_chainId" }).then(normalizeEvmChainId, () => void 0), timer(CHAIN_ANSWER_TIMEOUT_MS).pipe(map(() => void 0))));
|
|
28
|
+
const requestAccountsOnChain = async (provider) => {
|
|
29
|
+
const accountChanges = [];
|
|
30
|
+
const chainChanges = [];
|
|
31
|
+
const handleAccountsChanged = (addresses) => {
|
|
32
|
+
accountChanges.push(addresses);
|
|
33
|
+
};
|
|
34
|
+
const handleChainChanged = (chainId) => {
|
|
35
|
+
chainChanges.push(normalizeEvmChainId(chainId));
|
|
36
|
+
};
|
|
37
|
+
provider.on("accountsChanged", handleAccountsChanged);
|
|
38
|
+
provider.on("chainChanged", handleChainChanged);
|
|
39
|
+
try {
|
|
40
|
+
const addresses = await provider.request({ method: "eth_requestAccounts" });
|
|
41
|
+
const chainChangesBeforeRead = chainChanges.length;
|
|
42
|
+
const chainId = await readChainId(provider);
|
|
43
|
+
lastReported.set(provider, {
|
|
44
|
+
addresses: accountChanges.at(-1) ?? addresses,
|
|
45
|
+
chainId: chainChanges.length > chainChangesBeforeRead ? chainChanges.at(-1) : chainId
|
|
46
|
+
});
|
|
47
|
+
} finally {
|
|
48
|
+
provider.removeListener("accountsChanged", handleAccountsChanged);
|
|
49
|
+
provider.removeListener("chainChanged", handleChainChanged);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
25
52
|
const getInjectedWalletAccounts$ = (wallet) => {
|
|
26
53
|
if (!wallet.isConnected) return of([]);
|
|
27
54
|
return getCachedObservable$(`accounts:${wallet.id}`, () => new Observable((subscriber) => {
|
|
28
55
|
const addresses$ = new ReplaySubject(1);
|
|
29
56
|
const chainId$ = new ReplaySubject(1);
|
|
57
|
+
const reported = lastReported.get(wallet.provider);
|
|
58
|
+
if (reported) {
|
|
59
|
+
addresses$.next(reported.addresses);
|
|
60
|
+
chainId$.next(reported.chainId);
|
|
61
|
+
}
|
|
30
62
|
const getAccount = (address, chainId) => {
|
|
31
63
|
const client = createWalletClient({
|
|
32
64
|
account: address,
|
|
@@ -42,28 +74,47 @@ const getInjectedWalletAccounts$ = (wallet) => {
|
|
|
42
74
|
walletId: wallet.id
|
|
43
75
|
};
|
|
44
76
|
};
|
|
77
|
+
let accountEvents = 0;
|
|
78
|
+
let chainEvents = 0;
|
|
45
79
|
const handleAccountsChanged = (addrs) => {
|
|
80
|
+
accountEvents++;
|
|
46
81
|
addresses$.next(addrs);
|
|
47
82
|
};
|
|
48
83
|
const handleChainChanged = (chainIdHex) => {
|
|
84
|
+
chainEvents++;
|
|
49
85
|
chainId$.next(normalizeEvmChainId(chainIdHex));
|
|
50
86
|
};
|
|
51
87
|
const handleConnect = (connectInfo) => {
|
|
88
|
+
chainEvents++;
|
|
52
89
|
chainId$.next(normalizeEvmChainId(connectInfo?.chainId));
|
|
53
90
|
};
|
|
54
91
|
const handleDisconnect = () => {
|
|
92
|
+
chainEvents++;
|
|
55
93
|
chainId$.next(void 0);
|
|
56
94
|
};
|
|
57
95
|
wallet.provider.on("accountsChanged", handleAccountsChanged);
|
|
58
96
|
wallet.provider.on("chainChanged", handleChainChanged);
|
|
59
97
|
wallet.provider.on("connect", handleConnect);
|
|
60
98
|
wallet.provider.on("disconnect", handleDisconnect);
|
|
61
|
-
|
|
99
|
+
const accountEventsBeforeRead = accountEvents;
|
|
100
|
+
const accountsOutdated = () => accountEvents !== accountEventsBeforeRead;
|
|
101
|
+
wallet.provider.request({ method: "eth_accounts" }).then((addrs) => {
|
|
102
|
+
if (!accountsOutdated()) addresses$.next(addrs);
|
|
103
|
+
}).catch((err) => {
|
|
62
104
|
console.error("Failed to get accounts", err);
|
|
63
|
-
addresses$.next([]);
|
|
105
|
+
if (!accountsOutdated()) addresses$.next([]);
|
|
106
|
+
});
|
|
107
|
+
const chainEventsBeforeRead = chainEvents;
|
|
108
|
+
const chainOutdated = () => chainEvents !== chainEventsBeforeRead;
|
|
109
|
+
wallet.provider.request({ method: "eth_chainId" }).then((chainIdHex) => {
|
|
110
|
+
if (!chainOutdated()) chainId$.next(normalizeEvmChainId(chainIdHex));
|
|
111
|
+
}).catch(() => {
|
|
112
|
+
if (!chainOutdated()) chainId$.next(void 0);
|
|
64
113
|
});
|
|
65
|
-
|
|
66
|
-
|
|
114
|
+
const sub = combineLatest([addresses$, chainId$]).pipe(tap(([addresses, chainId]) => lastReported.set(wallet.provider, {
|
|
115
|
+
addresses,
|
|
116
|
+
chainId
|
|
117
|
+
})), map(([addresses, chainId]) => addresses.map((addr) => getAccount(addr, chainId)))).subscribe(subscriber);
|
|
67
118
|
return () => {
|
|
68
119
|
wallet.provider.removeListener("accountsChanged", handleAccountsChanged);
|
|
69
120
|
wallet.provider.removeListener("chainChanged", handleChainChanged);
|
|
@@ -187,9 +238,7 @@ const providersDetails$ = new Observable((subscriber) => {
|
|
|
187
238
|
const getEthereumWallets$ = (store) => createInjectedWallets$(store, {
|
|
188
239
|
sources$: providersDetails$,
|
|
189
240
|
getWalletId: (pd) => getWalletId("ethereum", pd.info.rdns),
|
|
190
|
-
connect:
|
|
191
|
-
await pd.provider.request({ method: "eth_requestAccounts" });
|
|
192
|
-
},
|
|
241
|
+
connect: (pd) => requestAccountsOnChain(pd.provider),
|
|
193
242
|
isUserRejection: isEip1193UserRejection,
|
|
194
243
|
onDisconnected: (walletId) => clearCachedObservable(`accounts:${walletId}`),
|
|
195
244
|
buildWallet: ({ source: pd, walletId, status, error, isConnected, connect, disconnect }) => ({
|
package/dist/ethereum.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethereum.mjs","names":["createMipdStore"],"sources":["../src/api/ethereum/accounts.ts","../src/api/ethereum/wallets.ts","../src/api/ethereum/plugin.ts"],"sourcesContent":["import {\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tof,\n\tReplaySubject,\n\tshareReplay,\n} from \"rxjs\";\nimport {\n\tcreateWalletClient,\n\tcustom,\n\ttype EIP1193Provider,\n\tgetAddress,\n} from \"viem\";\nimport { getWalletAccountId } from \"../../utils\";\nimport { getCachedObservable$ } from \"../../utils/getCachedObservable\";\nimport {\n\tcreatePlatformAccounts$,\n\tgetCaip10Addresses,\n\tgetSessionCaip10s,\n\ttype LiveWalletConnectWallet,\n} from \"../platformAccounts\";\nimport type { WalletConnectWallet } from \"../types\";\nimport type {\n\tEthereumAccount,\n\tEthereumInjectedWallet,\n\tEthereumWallet,\n} from \"./types\";\n\nconst normalizeEvmChainId = (value: unknown): number | undefined => {\n\tlet raw = value;\n\n\tif (typeof raw === \"string\" && raw.startsWith(\"eip155:\")) {\n\t\traw = raw.slice(\"eip155:\".length);\n\t}\n\n\tif (typeof raw === \"bigint\") {\n\t\treturn raw >= 0n ? Number(raw) : undefined;\n\t}\n\n\tif (typeof raw === \"number\") {\n\t\treturn Number.isInteger(raw) && raw >= 0 ? raw : undefined;\n\t}\n\n\tif (typeof raw === \"string\") {\n\t\tconst normalized = raw.trim().toLowerCase();\n\t\tif (!normalized) return undefined;\n\t\tconst parsed = normalized.startsWith(\"0x\")\n\t\t\t? Number.parseInt(normalized, 16)\n\t\t\t: Number.parseInt(normalized, 10);\n\t\treturn Number.isNaN(parsed) ? undefined : parsed;\n\t}\n\n\treturn undefined;\n};\n\nconst toCaipNetworkId = (value: unknown): string | undefined => {\n\tconst chainId = normalizeEvmChainId(value);\n\treturn chainId === undefined ? undefined : `eip155:${chainId}`;\n};\n\nconst getInjectedWalletAccounts$ = (\n\twallet: EthereumInjectedWallet,\n): Observable<EthereumAccount[]> => {\n\tif (!wallet.isConnected) return of([]);\n\n\treturn getCachedObservable$(`accounts:${wallet.id}`, () =>\n\t\tnew Observable<EthereumAccount[]>((subscriber) => {\n\t\t\tconst addresses$ = new ReplaySubject<string[]>(1);\n\t\t\tconst chainId$ = new ReplaySubject<number | undefined>(1);\n\n\t\t\tconst getAccount = (\n\t\t\t\taddress: string,\n\t\t\t\tchainId: number | undefined,\n\t\t\t): EthereumAccount => {\n\t\t\t\tconst client = createWalletClient({\n\t\t\t\t\taccount: address as `0x${string}`,\n\t\t\t\t\ttransport: custom(wallet.provider as EIP1193Provider),\n\t\t\t\t});\n\n\t\t\t\treturn {\n\t\t\t\t\tid: getWalletAccountId(wallet.id, address),\n\t\t\t\t\tplatform: \"ethereum\",\n\t\t\t\t\tclient,\n\t\t\t\t\taddress: getAddress(address),\n\t\t\t\t\tchainId,\n\t\t\t\t\twalletName: wallet.name,\n\t\t\t\t\twalletId: wallet.id,\n\t\t\t\t};\n\t\t\t};\n\n\t\t\tconst handleAccountsChanged = (addrs: string[]) => {\n\t\t\t\taddresses$.next(addrs);\n\t\t\t};\n\n\t\t\tconst handleChainChanged = (chainIdHex: unknown) => {\n\t\t\t\tchainId$.next(normalizeEvmChainId(chainIdHex));\n\t\t\t};\n\n\t\t\tconst handleConnect = (connectInfo: { chainId?: unknown }) => {\n\t\t\t\tchainId$.next(normalizeEvmChainId(connectInfo?.chainId));\n\t\t\t};\n\n\t\t\tconst handleDisconnect = () => {\n\t\t\t\tchainId$.next(undefined);\n\t\t\t};\n\n\t\t\t// Subscribe to provider events\n\t\t\twallet.provider.on(\"accountsChanged\", handleAccountsChanged);\n\t\t\twallet.provider.on(\"chainChanged\", handleChainChanged);\n\t\t\twallet.provider.on(\"connect\", handleConnect);\n\t\t\twallet.provider.on(\"disconnect\", handleDisconnect);\n\n\t\t\t// Fetch initial values\n\t\t\twallet.provider\n\t\t\t\t.request({ method: \"eth_accounts\" })\n\t\t\t\t.then((addrs: string[]) => addresses$.next(addrs))\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tconsole.error(\"Failed to get accounts\", err);\n\t\t\t\t\taddresses$.next([]);\n\t\t\t\t});\n\n\t\t\twallet.provider\n\t\t\t\t.request({ method: \"eth_chainId\" })\n\t\t\t\t.then(handleChainChanged)\n\t\t\t\t.catch(() => chainId$.next(undefined));\n\n\t\t\t// Combine addresses + chainId into account list\n\t\t\tconst sub = combineLatest([addresses$, chainId$])\n\t\t\t\t.pipe(\n\t\t\t\t\tmap(([addresses, chainId]) =>\n\t\t\t\t\t\taddresses.map((addr) => getAccount(addr, chainId)),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.subscribe(subscriber);\n\n\t\t\treturn () => {\n\t\t\t\twallet.provider.removeListener(\n\t\t\t\t\t\"accountsChanged\",\n\t\t\t\t\thandleAccountsChanged,\n\t\t\t\t);\n\t\t\t\twallet.provider.removeListener(\"chainChanged\", handleChainChanged);\n\t\t\t\twallet.provider.removeListener(\"connect\", handleConnect);\n\t\t\t\twallet.provider.removeListener(\"disconnect\", handleDisconnect);\n\t\t\t\tsub.unsubscribe();\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n\nconst wrapWalletConnectProvider = (\n\tprovider: EIP1193Provider,\n\tsessionTopic: string,\n\tcaipNetworkId: string | undefined,\n): EIP1193Provider => {\n\treturn new Proxy(provider, {\n\t\tget(target, prop, receiver) {\n\t\t\tif (prop !== \"request\") return Reflect.get(target, prop, receiver);\n\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: EIP-1193 request args\n\t\t\treturn (args: any) => {\n\t\t\t\tif (!args || typeof args !== \"object\" || !args.method)\n\t\t\t\t\treturn target.request(args);\n\t\t\t\t// Build a new object rather than mutating the caller's args: the\n\t\t\t\t// EIP-1193 request object is owned by viem and may be frozen or reused.\n\t\t\t\tconst next = { ...args };\n\t\t\t\tif (next.topic === undefined) next.topic = sessionTopic;\n\t\t\t\tif (next.chainId === undefined && caipNetworkId !== undefined)\n\t\t\t\t\tnext.chainId = caipNetworkId;\n\t\t\t\t// WalletConnect's UniversalProvider reads the target CAIP chain id from\n\t\t\t\t// the SECOND positional argument of `request(args, chainId)`, not from a\n\t\t\t\t// field on the args object. This AppKit instance has no native eip155\n\t\t\t\t// adapter, so the provider has no default chain — without the positional\n\t\t\t\t// chain id every call is rejected (\"Unsupported chains\" / \"Method not\n\t\t\t\t// found\"). Pass it positionally so the request routes to the session's\n\t\t\t\t// chain.\n\t\t\t\treturn (\n\t\t\t\t\ttarget.request as (a: unknown, chainId?: string) => Promise<unknown>\n\t\t\t\t)(next, caipNetworkId);\n\t\t\t};\n\t\t},\n\t});\n};\n\nconst sameAddresses = (a: string[], b: string[]) =>\n\ta.length === b.length && a.every((addr, i) => addr === b[i]);\n\nconst getWalletConnectAccounts$ = (\n\twallet: LiveWalletConnectWallet,\n): Observable<EthereumAccount[]> => {\n\tconst provider = wallet.appKit.getProvider(\"eip155\");\n\n\tif (!wallet.platforms.includes(\"ethereum\") || !provider?.session)\n\t\treturn of([]);\n\n\treturn getCachedObservable$(`accounts:${wallet.id}:ethereum:`, () =>\n\t\tnew Observable<EthereumAccount[]>((subscriber) => {\n\t\t\tconst caipNetworkId$ = new ReplaySubject<string | undefined>(1);\n\t\t\tconst addresses$ = new ReplaySubject<string[]>(1);\n\n\t\t\t// AppKit's getAccount(\"eip155\").allAccounts is empty because this AppKit\n\t\t\t// instance has no native eip155 adapter — eip155 runs through the\n\t\t\t// WalletConnect UniversalProvider, so the session is the source of truth\n\t\t\t// (mirrors the polkadot/solana AppKit paths). Accounts are CAIP-10 strings\n\t\t\t// (\"eip155:<chainRef>:<address>\"), one entry per chain, so dedupe to unique\n\t\t\t// addresses. Read live on each change so switching/adding accounts is\n\t\t\t// reflected.\n\t\t\tconst readAddresses = (): string[] => {\n\t\t\t\tconst session = provider.session;\n\t\t\t\tif (!session) return [];\n\t\t\t\tconst addresses = new Set<string>();\n\t\t\t\tfor (const raw of getCaip10Addresses(\n\t\t\t\t\tgetSessionCaip10s(session, \"eip155\"),\n\t\t\t\t)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\taddresses.add(getAddress(raw));\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// skip malformed CAIP-10 address\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn [...addresses];\n\t\t\t};\n\n\t\t\t// Derive the CAIP network id from the session's eip155 CAIP-10 accounts\n\t\t\t// (\"eip155:<ref>:<addr>\") as a synchronous fallback for eth_chainId.\n\t\t\tconst readCaipNetworkId = (): string | undefined => {\n\t\t\t\tconst session = provider.session;\n\t\t\t\tif (!session) return undefined;\n\t\t\t\tfor (const account of getSessionCaip10s(session, \"eip155\")) {\n\t\t\t\t\tconst ref = account.split(\":\")[1];\n\t\t\t\t\tif (ref) return `eip155:${ref}`;\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t};\n\n\t\t\tconst handleChainChanged = (chainId: unknown) => {\n\t\t\t\tconst caipNetworkId = toCaipNetworkId(chainId);\n\t\t\t\tif (caipNetworkId) {\n\t\t\t\t\tcaipNetworkId$.next(caipNetworkId);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst handleAccountsChanged = () => addresses$.next(readAddresses());\n\n\t\t\tprovider.on(\"chainChanged\", handleChainChanged);\n\t\t\tprovider.on(\"accountsChanged\", handleAccountsChanged);\n\t\t\tprovider.on(\"session_update\", handleAccountsChanged);\n\t\t\t// Seed the chain id from the session synchronously so the account list can\n\t\t\t// surface even if eth_chainId never resolves; eth_chainId then refines it.\n\t\t\t// Without this seed, combineLatest below never fires when eth_chainId\n\t\t\t// rejects or returns an unparseable value, and the accounts silently never\n\t\t\t// appear (the injected path seeds undefined on failure for the same reason).\n\t\t\tcaipNetworkId$.next(readCaipNetworkId());\n\t\t\tprovider\n\t\t\t\t.request({ method: \"eth_chainId\" })\n\t\t\t\t.then(handleChainChanged)\n\t\t\t\t.catch(() => {});\n\t\t\taddresses$.next(readAddresses());\n\n\t\t\tconst sub = combineLatest([\n\t\t\t\tcaipNetworkId$.pipe(distinctUntilChanged()),\n\t\t\t\taddresses$.pipe(distinctUntilChanged(sameAddresses)),\n\t\t\t])\n\t\t\t\t.pipe(\n\t\t\t\t\tmap(([caipNetworkId, addresses]) => {\n\t\t\t\t\t\tconst chainId = normalizeEvmChainId(caipNetworkId);\n\t\t\t\t\t\tconst transport = custom(\n\t\t\t\t\t\t\twrapWalletConnectProvider(\n\t\t\t\t\t\t\t\tprovider as unknown as EIP1193Provider,\n\t\t\t\t\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: legacy\n\t\t\t\t\t\t\t\tprovider.session!.topic,\n\t\t\t\t\t\t\t\tcaipNetworkId,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn addresses.map((addr): EthereumAccount => {\n\t\t\t\t\t\t\tconst client = createWalletClient({\n\t\t\t\t\t\t\t\taccount: addr as `0x${string}`,\n\t\t\t\t\t\t\t\ttransport,\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tid: getWalletAccountId(wallet.id, addr),\n\t\t\t\t\t\t\t\tplatform: \"ethereum\",\n\t\t\t\t\t\t\t\twalletName: wallet.name,\n\t\t\t\t\t\t\t\twalletId: wallet.id,\n\t\t\t\t\t\t\t\taddress: addr as `0x${string}`,\n\t\t\t\t\t\t\t\tclient,\n\t\t\t\t\t\t\t\tchainId,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t});\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.subscribe(subscriber);\n\n\t\t\treturn () => {\n\t\t\t\tprovider.off(\"chainChanged\", handleChainChanged);\n\t\t\t\tprovider.off(\"accountsChanged\", handleAccountsChanged);\n\t\t\t\tprovider.off(\"session_update\", handleAccountsChanged);\n\t\t\t\tsub.unsubscribe();\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n\nexport const getEthereumAccounts$ = (\n\tethereumWallets: Observable<(EthereumWallet | WalletConnectWallet)[]>,\n) =>\n\tcreatePlatformAccounts$({\n\t\twallets$: ethereumWallets,\n\t\tgetInjectedAccounts$: getInjectedWalletAccounts$,\n\t\tgetWalletConnectAccounts$,\n\t\t// Re-emit on chain switches, not just account id changes.\n\t\taccountChangeKey: (account) => `${account.id}|${account.chainId ?? \"\"}`,\n\t});\n","import {\n\tcreateStore as createMipdStore,\n\ttype EIP6963ProviderDetail,\n} from \"mipd\";\nimport { Observable, shareReplay } from \"rxjs\";\nimport type { EIP1193Provider } from \"viem\";\nimport { clearCachedObservable } from \"../../utils/getCachedObservable\";\nimport { getWalletId } from \"../../utils/WalletId\";\nimport { isEip1193UserRejection } from \"../errors\";\nimport { createInjectedWallets$ } from \"../injectedWallets\";\nimport type { KheopskitStore } from \"../store\";\nimport type { EthereumInjectedWallet } from \"./types\";\n\n/**\n * Observable that emits EIP-6963 provider details from injected wallets.\n * Returns empty array during SSR since browser wallet APIs are not available.\n */\nconst providersDetails$ = new Observable<EIP6963ProviderDetail[]>(\n\t(subscriber) => {\n\t\t// Guard against SSR - mipd requires browser APIs\n\t\tif (typeof window === \"undefined\") {\n\t\t\tsubscriber.next([]);\n\t\t\treturn () => {};\n\t\t}\n\n\t\tconst mipdStore = createMipdStore();\n\n\t\tconst unsubscribe = mipdStore.subscribe((providerDetails) => {\n\t\t\tsubscriber.next(providerDetails as EIP6963ProviderDetail[]);\n\t\t});\n\n\t\tconst providerDetails = mipdStore.getProviders();\n\n\t\tsubscriber.next(providerDetails as EIP6963ProviderDetail[]);\n\n\t\treturn () => {\n\t\t\tunsubscribe();\n\t\t\tmipdStore.destroy();\n\t\t};\n\t},\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\n// The shared WalletConnect connector is emitted once by core (see\n// `getWallets$`), not per platform — so this returns only injected wallets.\nexport const getEthereumWallets$ = (store: KheopskitStore) =>\n\tcreateInjectedWallets$<EIP6963ProviderDetail, EthereumInjectedWallet>(store, {\n\t\tsources$: providersDetails$,\n\t\tgetWalletId: (pd) => getWalletId(\"ethereum\", pd.info.rdns),\n\t\tconnect: async (pd) => {\n\t\t\tawait (pd.provider as EIP1193Provider).request({\n\t\t\t\tmethod: \"eth_requestAccounts\",\n\t\t\t});\n\t\t},\n\t\tisUserRejection: isEip1193UserRejection,\n\t\t// Drop the cached account observable so a later reconnect rebuilds it\n\t\t// against the current provider, not a stale closure.\n\t\tonDisconnected: (walletId) => clearCachedObservable(`accounts:${walletId}`),\n\t\tbuildWallet: ({\n\t\t\tsource: pd,\n\t\t\twalletId,\n\t\t\tstatus,\n\t\t\terror,\n\t\t\tisConnected,\n\t\t\tconnect,\n\t\t\tdisconnect,\n\t\t}) => ({\n\t\t\tplatform: \"ethereum\",\n\t\t\ttype: \"injected\",\n\t\t\tid: walletId,\n\t\t\tname: pd.info.name,\n\t\t\ticon: pd.info.icon,\n\t\t\tprovider: pd.provider as EIP1193Provider,\n\t\t\tstatus,\n\t\t\terror,\n\t\t\tisConnected,\n\t\t\tsourceId: pd.info.rdns,\n\t\t\tconnect,\n\t\t\tdisconnect,\n\t\t}),\n\t});\n","import type { KheopskitPlatform, PlatformContext } from \"../types\";\nimport { getEthereumAccounts$ } from \"./accounts\";\nimport type { EthereumAccount, EthereumWallet } from \"./types\";\nimport { getEthereumWallets$ } from \"./wallets\";\n\n/**\n * Ethereum platform plugin. Pass to `createKheopskit({ platforms: [ethereum()] })`.\n *\n * @example\n * ```ts\n * import { ethereum } from \"@kheopskit/core/ethereum\";\n * ethereum();\n * ```\n */\nexport const ethereum = (): KheopskitPlatform<\n\t\"ethereum\",\n\tEthereumWallet,\n\tEthereumAccount\n> => ({\n\tplatform: \"ethereum\",\n\tgetWallets$: (ctx: PlatformContext) => getEthereumWallets$(ctx.store),\n\tgetAccounts$: (wallets$) => getEthereumAccounts$(wallets$),\n});\n"],"mappings":";;;;;;;;AA8BA,MAAM,uBAAuB,UAAuC;CACnE,IAAI,MAAM;CAEV,IAAI,OAAO,QAAQ,YAAY,IAAI,WAAW,SAAS,GACtD,MAAM,IAAI,MAAM,CAAgB;CAGjC,IAAI,OAAO,QAAQ,UAClB,OAAO,OAAO,KAAK,OAAO,GAAG,IAAI,KAAA;CAGlC,IAAI,OAAO,QAAQ,UAClB,OAAO,OAAO,UAAU,GAAG,KAAK,OAAO,IAAI,MAAM,KAAA;CAGlD,IAAI,OAAO,QAAQ,UAAU;EAC5B,MAAM,aAAa,IAAI,KAAK,CAAC,CAAC,YAAY;EAC1C,IAAI,CAAC,YAAY,OA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ACZ,YAAY;EACZ,UAAU,QAAQ;CACnB;AACD,CACD,CAAC,CAAC,KAAK,YAAY;CAAE,UAAU;CAAM,YAAY;AAAE,CAAC,CAAC;AAIrD,MAAa,uBAAuB,UACnC,uBAAsE,OAAO;CAC5E,UAAU;CACV,cAAc,OAAO,YAAY,YAAY,GAAG,KAAK,IAAI;CACzD,SAAS,OAAO,OAAO;EACtB,MAAO,GAAG,SAA6B,QAAQ,EAC9C,QAAQ,sBACT,CAAC;CACF;CACA,iBAAiB;CAGjB,iBAAiB,aAAa,sBAAsB,YAAY,UAAU;CAC1E,cAAc,EACb,QAAQ,IACR,UACA,QACA,OACA,aACA,SACA,kBACM;EACN,UAAU;EACV,MAAM;EACN,IAAI;EACJ,MAAM,GAAG,KAAK;EACd,MAAM,GAAG,KAAK;EACd,UAAU,GAAG;EACb;EACA;EACA;EACA,UAAU,GAAG,KAAK;EAClB;EACA;CACD;AACD,CAAC;;;;;;;;;;;;ACjEF,MAAa,kBAIP;CACL,UAAU;CACV,cAAc,QAAyB,oBAAoB,IAAI,KAAK;CACpE,eAAe,aAAa,qBAAqB,QAAQ;AAC1D"}
|
|
1
|
+
{"version":3,"file":"ethereum.mjs","names":["createMipdStore"],"sources":["../src/api/ethereum/accounts.ts","../src/api/ethereum/wallets.ts","../src/api/ethereum/plugin.ts"],"sourcesContent":["import {\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tfirstValueFrom,\n\tmap,\n\tObservable,\n\tof,\n\tReplaySubject,\n\trace,\n\tshareReplay,\n\ttap,\n\ttimer,\n} from \"rxjs\";\nimport {\n\tcreateWalletClient,\n\tcustom,\n\ttype EIP1193Provider,\n\tgetAddress,\n} from \"viem\";\nimport { getWalletAccountId } from \"../../utils\";\nimport { getCachedObservable$ } from \"../../utils/getCachedObservable\";\nimport {\n\tcreatePlatformAccounts$,\n\tgetCaip10Addresses,\n\tgetSessionCaip10s,\n\ttype LiveWalletConnectWallet,\n} from \"../platformAccounts\";\nimport type { WalletConnectWallet } from \"../types\";\nimport type {\n\tEthereumAccount,\n\tEthereumInjectedWallet,\n\tEthereumWallet,\n} from \"./types\";\n\nconst normalizeEvmChainId = (value: unknown): number | undefined => {\n\tlet raw = value;\n\n\tif (typeof raw === \"string\" && raw.startsWith(\"eip155:\")) {\n\t\traw = raw.slice(\"eip155:\".length);\n\t}\n\n\tif (typeof raw === \"bigint\") {\n\t\treturn raw >= 0n ? Number(raw) : undefined;\n\t}\n\n\tif (typeof raw === \"number\") {\n\t\treturn Number.isInteger(raw) && raw >= 0 ? raw : undefined;\n\t}\n\n\tif (typeof raw === \"string\") {\n\t\tconst normalized = raw.trim().toLowerCase();\n\t\tif (!normalized) return undefined;\n\t\tconst parsed = normalized.startsWith(\"0x\")\n\t\t\t? Number.parseInt(normalized, 16)\n\t\t\t: Number.parseInt(normalized, 10);\n\t\treturn Number.isNaN(parsed) ? undefined : parsed;\n\t}\n\n\treturn undefined;\n};\n\nconst toCaipNetworkId = (value: unknown): string | undefined => {\n\tconst chainId = normalizeEvmChainId(value);\n\treturn chainId === undefined ? undefined : `eip155:${chainId}`;\n};\n\ntype ReportedAccounts = { addresses: string[]; chainId: number | undefined };\n\nconst lastReported = new WeakMap<EIP1193Provider, ReportedAccounts>();\n\nconst CHAIN_ANSWER_TIMEOUT_MS = 2_000;\n\nconst readChainId = (provider: EIP1193Provider) =>\n\tfirstValueFrom(\n\t\trace(\n\t\t\tprovider\n\t\t\t\t.request({ method: \"eth_chainId\" })\n\t\t\t\t.then(normalizeEvmChainId, () => undefined),\n\t\t\ttimer(CHAIN_ANSWER_TIMEOUT_MS).pipe(map(() => undefined)),\n\t\t),\n\t);\n\nexport const requestAccountsOnChain = async (provider: EIP1193Provider) => {\n\tconst accountChanges: string[][] = [];\n\tconst chainChanges: (number | undefined)[] = [];\n\tconst handleAccountsChanged = (addresses: string[]) => {\n\t\taccountChanges.push(addresses);\n\t};\n\tconst handleChainChanged = (chainId: unknown) => {\n\t\tchainChanges.push(normalizeEvmChainId(chainId));\n\t};\n\tprovider.on(\"accountsChanged\", handleAccountsChanged);\n\tprovider.on(\"chainChanged\", handleChainChanged);\n\ttry {\n\t\tconst addresses = await provider.request({\n\t\t\tmethod: \"eth_requestAccounts\",\n\t\t});\n\t\tconst chainChangesBeforeRead = chainChanges.length;\n\t\tconst chainId = await readChainId(provider);\n\t\tlastReported.set(provider, {\n\t\t\taddresses: accountChanges.at(-1) ?? addresses,\n\t\t\tchainId:\n\t\t\t\tchainChanges.length > chainChangesBeforeRead\n\t\t\t\t\t? chainChanges.at(-1)\n\t\t\t\t\t: chainId,\n\t\t});\n\t} finally {\n\t\tprovider.removeListener(\"accountsChanged\", handleAccountsChanged);\n\t\tprovider.removeListener(\"chainChanged\", handleChainChanged);\n\t}\n};\n\nconst getInjectedWalletAccounts$ = (\n\twallet: EthereumInjectedWallet,\n): Observable<EthereumAccount[]> => {\n\tif (!wallet.isConnected) return of([]);\n\n\treturn getCachedObservable$(`accounts:${wallet.id}`, () =>\n\t\tnew Observable<EthereumAccount[]>((subscriber) => {\n\t\t\tconst addresses$ = new ReplaySubject<string[]>(1);\n\t\t\tconst chainId$ = new ReplaySubject<number | undefined>(1);\n\t\t\tconst reported = lastReported.get(wallet.provider);\n\t\t\tif (reported) {\n\t\t\t\taddresses$.next(reported.addresses);\n\t\t\t\tchainId$.next(reported.chainId);\n\t\t\t}\n\n\t\t\tconst getAccount = (\n\t\t\t\taddress: string,\n\t\t\t\tchainId: number | undefined,\n\t\t\t): EthereumAccount => {\n\t\t\t\tconst client = createWalletClient({\n\t\t\t\t\taccount: address as `0x${string}`,\n\t\t\t\t\ttransport: custom(wallet.provider as EIP1193Provider),\n\t\t\t\t});\n\n\t\t\t\treturn {\n\t\t\t\t\tid: getWalletAccountId(wallet.id, address),\n\t\t\t\t\tplatform: \"ethereum\",\n\t\t\t\t\tclient,\n\t\t\t\t\taddress: getAddress(address),\n\t\t\t\t\tchainId,\n\t\t\t\t\twalletName: wallet.name,\n\t\t\t\t\twalletId: wallet.id,\n\t\t\t\t};\n\t\t\t};\n\n\t\t\tlet accountEvents = 0;\n\t\t\tlet chainEvents = 0;\n\n\t\t\tconst handleAccountsChanged = (addrs: string[]) => {\n\t\t\t\taccountEvents++;\n\t\t\t\taddresses$.next(addrs);\n\t\t\t};\n\n\t\t\tconst handleChainChanged = (chainIdHex: unknown) => {\n\t\t\t\tchainEvents++;\n\t\t\t\tchainId$.next(normalizeEvmChainId(chainIdHex));\n\t\t\t};\n\n\t\t\tconst handleConnect = (connectInfo: { chainId?: unknown }) => {\n\t\t\t\tchainEvents++;\n\t\t\t\tchainId$.next(normalizeEvmChainId(connectInfo?.chainId));\n\t\t\t};\n\n\t\t\tconst handleDisconnect = () => {\n\t\t\t\tchainEvents++;\n\t\t\t\tchainId$.next(undefined);\n\t\t\t};\n\n\t\t\t// Subscribe to provider events\n\t\t\twallet.provider.on(\"accountsChanged\", handleAccountsChanged);\n\t\t\twallet.provider.on(\"chainChanged\", handleChainChanged);\n\t\t\twallet.provider.on(\"connect\", handleConnect);\n\t\t\twallet.provider.on(\"disconnect\", handleDisconnect);\n\n\t\t\tconst accountEventsBeforeRead = accountEvents;\n\t\t\tconst accountsOutdated = () => accountEvents !== accountEventsBeforeRead;\n\t\t\twallet.provider\n\t\t\t\t.request({ method: \"eth_accounts\" })\n\t\t\t\t.then((addrs: string[]) => {\n\t\t\t\t\tif (!accountsOutdated()) addresses$.next(addrs);\n\t\t\t\t})\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tconsole.error(\"Failed to get accounts\", err);\n\t\t\t\t\tif (!accountsOutdated()) addresses$.next([]);\n\t\t\t\t});\n\n\t\t\tconst chainEventsBeforeRead = chainEvents;\n\t\t\tconst chainOutdated = () => chainEvents !== chainEventsBeforeRead;\n\t\t\twallet.provider\n\t\t\t\t.request({ method: \"eth_chainId\" })\n\t\t\t\t.then((chainIdHex: unknown) => {\n\t\t\t\t\tif (!chainOutdated()) chainId$.next(normalizeEvmChainId(chainIdHex));\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\tif (!chainOutdated()) chainId$.next(undefined);\n\t\t\t\t});\n\n\t\t\t// Combine addresses + chainId into account list\n\t\t\tconst sub = combineLatest([addresses$, chainId$])\n\t\t\t\t.pipe(\n\t\t\t\t\ttap(([addresses, chainId]) =>\n\t\t\t\t\t\tlastReported.set(wallet.provider, { addresses, chainId }),\n\t\t\t\t\t),\n\t\t\t\t\tmap(([addresses, chainId]) =>\n\t\t\t\t\t\taddresses.map((addr) => getAccount(addr, chainId)),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.subscribe(subscriber);\n\n\t\t\treturn () => {\n\t\t\t\twallet.provider.removeListener(\n\t\t\t\t\t\"accountsChanged\",\n\t\t\t\t\thandleAccountsChanged,\n\t\t\t\t);\n\t\t\t\twallet.provider.removeListener(\"chainChanged\", handleChainChanged);\n\t\t\t\twallet.provider.removeListener(\"connect\", handleConnect);\n\t\t\t\twallet.provider.removeListener(\"disconnect\", handleDisconnect);\n\t\t\t\tsub.unsubscribe();\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n\nconst wrapWalletConnectProvider = (\n\tprovider: EIP1193Provider,\n\tsessionTopic: string,\n\tcaipNetworkId: string | undefined,\n): EIP1193Provider => {\n\treturn new Proxy(provider, {\n\t\tget(target, prop, receiver) {\n\t\t\tif (prop !== \"request\") return Reflect.get(target, prop, receiver);\n\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: EIP-1193 request args\n\t\t\treturn (args: any) => {\n\t\t\t\tif (!args || typeof args !== \"object\" || !args.method)\n\t\t\t\t\treturn target.request(args);\n\t\t\t\t// Build a new object rather than mutating the caller's args: the\n\t\t\t\t// EIP-1193 request object is owned by viem and may be frozen or reused.\n\t\t\t\tconst next = { ...args };\n\t\t\t\tif (next.topic === undefined) next.topic = sessionTopic;\n\t\t\t\tif (next.chainId === undefined && caipNetworkId !== undefined)\n\t\t\t\t\tnext.chainId = caipNetworkId;\n\t\t\t\t// WalletConnect's UniversalProvider reads the target CAIP chain id from\n\t\t\t\t// the SECOND positional argument of `request(args, chainId)`, not from a\n\t\t\t\t// field on the args object. This AppKit instance has no native eip155\n\t\t\t\t// adapter, so the provider has no default chain — without the positional\n\t\t\t\t// chain id every call is rejected (\"Unsupported chains\" / \"Method not\n\t\t\t\t// found\"). Pass it positionally so the request routes to the session's\n\t\t\t\t// chain.\n\t\t\t\treturn (\n\t\t\t\t\ttarget.request as (a: unknown, chainId?: string) => Promise<unknown>\n\t\t\t\t)(next, caipNetworkId);\n\t\t\t};\n\t\t},\n\t});\n};\n\nconst sameAddresses = (a: string[], b: string[]) =>\n\ta.length === b.length && a.every((addr, i) => addr === b[i]);\n\nconst getWalletConnectAccounts$ = (\n\twallet: LiveWalletConnectWallet,\n): Observable<EthereumAccount[]> => {\n\tconst provider = wallet.appKit.getProvider(\"eip155\");\n\n\tif (!wallet.platforms.includes(\"ethereum\") || !provider?.session)\n\t\treturn of([]);\n\n\treturn getCachedObservable$(`accounts:${wallet.id}:ethereum:`, () =>\n\t\tnew Observable<EthereumAccount[]>((subscriber) => {\n\t\t\tconst caipNetworkId$ = new ReplaySubject<string | undefined>(1);\n\t\t\tconst addresses$ = new ReplaySubject<string[]>(1);\n\n\t\t\t// AppKit's getAccount(\"eip155\").allAccounts is empty because this AppKit\n\t\t\t// instance has no native eip155 adapter — eip155 runs through the\n\t\t\t// WalletConnect UniversalProvider, so the session is the source of truth\n\t\t\t// (mirrors the polkadot/solana AppKit paths). Accounts are CAIP-10 strings\n\t\t\t// (\"eip155:<chainRef>:<address>\"), one entry per chain, so dedupe to unique\n\t\t\t// addresses. Read live on each change so switching/adding accounts is\n\t\t\t// reflected.\n\t\t\tconst readAddresses = (): string[] => {\n\t\t\t\tconst session = provider.session;\n\t\t\t\tif (!session) return [];\n\t\t\t\tconst addresses = new Set<string>();\n\t\t\t\tfor (const raw of getCaip10Addresses(\n\t\t\t\t\tgetSessionCaip10s(session, \"eip155\"),\n\t\t\t\t)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\taddresses.add(getAddress(raw));\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// skip malformed CAIP-10 address\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn [...addresses];\n\t\t\t};\n\n\t\t\t// Derive the CAIP network id from the session's eip155 CAIP-10 accounts\n\t\t\t// (\"eip155:<ref>:<addr>\") as a synchronous fallback for eth_chainId.\n\t\t\tconst readCaipNetworkId = (): string | undefined => {\n\t\t\t\tconst session = provider.session;\n\t\t\t\tif (!session) return undefined;\n\t\t\t\tfor (const account of getSessionCaip10s(session, \"eip155\")) {\n\t\t\t\t\tconst ref = account.split(\":\")[1];\n\t\t\t\t\tif (ref) return `eip155:${ref}`;\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t};\n\n\t\t\tconst handleChainChanged = (chainId: unknown) => {\n\t\t\t\tconst caipNetworkId = toCaipNetworkId(chainId);\n\t\t\t\tif (caipNetworkId) {\n\t\t\t\t\tcaipNetworkId$.next(caipNetworkId);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst handleAccountsChanged = () => addresses$.next(readAddresses());\n\n\t\t\tprovider.on(\"chainChanged\", handleChainChanged);\n\t\t\tprovider.on(\"accountsChanged\", handleAccountsChanged);\n\t\t\tprovider.on(\"session_update\", handleAccountsChanged);\n\t\t\t// Seed the chain id from the session synchronously so the account list can\n\t\t\t// surface even if eth_chainId never resolves; eth_chainId then refines it.\n\t\t\t// Without this seed, combineLatest below never fires when eth_chainId\n\t\t\t// rejects or returns an unparseable value, and the accounts silently never\n\t\t\t// appear (the injected path seeds undefined on failure for the same reason).\n\t\t\tcaipNetworkId$.next(readCaipNetworkId());\n\t\t\tprovider\n\t\t\t\t.request({ method: \"eth_chainId\" })\n\t\t\t\t.then(handleChainChanged)\n\t\t\t\t.catch(() => {});\n\t\t\taddresses$.next(readAddresses());\n\n\t\t\tconst sub = combineLatest([\n\t\t\t\tcaipNetworkId$.pipe(distinctUntilChanged()),\n\t\t\t\taddresses$.pipe(distinctUntilChanged(sameAddresses)),\n\t\t\t])\n\t\t\t\t.pipe(\n\t\t\t\t\tmap(([caipNetworkId, addresses]) => {\n\t\t\t\t\t\tconst chainId = normalizeEvmChainId(caipNetworkId);\n\t\t\t\t\t\tconst transport = custom(\n\t\t\t\t\t\t\twrapWalletConnectProvider(\n\t\t\t\t\t\t\t\tprovider as unknown as EIP1193Provider,\n\t\t\t\t\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: legacy\n\t\t\t\t\t\t\t\tprovider.session!.topic,\n\t\t\t\t\t\t\t\tcaipNetworkId,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn addresses.map((addr): EthereumAccount => {\n\t\t\t\t\t\t\tconst client = createWalletClient({\n\t\t\t\t\t\t\t\taccount: addr as `0x${string}`,\n\t\t\t\t\t\t\t\ttransport,\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tid: getWalletAccountId(wallet.id, addr),\n\t\t\t\t\t\t\t\tplatform: \"ethereum\",\n\t\t\t\t\t\t\t\twalletName: wallet.name,\n\t\t\t\t\t\t\t\twalletId: wallet.id,\n\t\t\t\t\t\t\t\taddress: addr as `0x${string}`,\n\t\t\t\t\t\t\t\tclient,\n\t\t\t\t\t\t\t\tchainId,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t});\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.subscribe(subscriber);\n\n\t\t\treturn () => {\n\t\t\t\tprovider.off(\"chainChanged\", handleChainChanged);\n\t\t\t\tprovider.off(\"accountsChanged\", handleAccountsChanged);\n\t\t\t\tprovider.off(\"session_update\", handleAccountsChanged);\n\t\t\t\tsub.unsubscribe();\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n\nexport const getEthereumAccounts$ = (\n\tethereumWallets: Observable<(EthereumWallet | WalletConnectWallet)[]>,\n) =>\n\tcreatePlatformAccounts$({\n\t\twallets$: ethereumWallets,\n\t\tgetInjectedAccounts$: getInjectedWalletAccounts$,\n\t\tgetWalletConnectAccounts$,\n\t\t// Re-emit on chain switches, not just account id changes.\n\t\taccountChangeKey: (account) => `${account.id}|${account.chainId ?? \"\"}`,\n\t});\n","import {\n\tcreateStore as createMipdStore,\n\ttype EIP6963ProviderDetail,\n} from \"mipd\";\nimport { Observable, shareReplay } from \"rxjs\";\nimport type { EIP1193Provider } from \"viem\";\nimport { clearCachedObservable } from \"../../utils/getCachedObservable\";\nimport { getWalletId } from \"../../utils/WalletId\";\nimport { isEip1193UserRejection } from \"../errors\";\nimport { createInjectedWallets$ } from \"../injectedWallets\";\nimport type { KheopskitStore } from \"../store\";\nimport { requestAccountsOnChain } from \"./accounts\";\nimport type { EthereumInjectedWallet } from \"./types\";\n\n/**\n * Observable that emits EIP-6963 provider details from injected wallets.\n * Returns empty array during SSR since browser wallet APIs are not available.\n */\nconst providersDetails$ = new Observable<EIP6963ProviderDetail[]>(\n\t(subscriber) => {\n\t\t// Guard against SSR - mipd requires browser APIs\n\t\tif (typeof window === \"undefined\") {\n\t\t\tsubscriber.next([]);\n\t\t\treturn () => {};\n\t\t}\n\n\t\tconst mipdStore = createMipdStore();\n\n\t\tconst unsubscribe = mipdStore.subscribe((providerDetails) => {\n\t\t\tsubscriber.next(providerDetails as EIP6963ProviderDetail[]);\n\t\t});\n\n\t\tconst providerDetails = mipdStore.getProviders();\n\n\t\tsubscriber.next(providerDetails as EIP6963ProviderDetail[]);\n\n\t\treturn () => {\n\t\t\tunsubscribe();\n\t\t\tmipdStore.destroy();\n\t\t};\n\t},\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\n// The shared WalletConnect connector is emitted once by core (see\n// `getWallets$`), not per platform — so this returns only injected wallets.\nexport const getEthereumWallets$ = (store: KheopskitStore) =>\n\tcreateInjectedWallets$<EIP6963ProviderDetail, EthereumInjectedWallet>(store, {\n\t\tsources$: providersDetails$,\n\t\tgetWalletId: (pd) => getWalletId(\"ethereum\", pd.info.rdns),\n\t\tconnect: (pd) => requestAccountsOnChain(pd.provider as EIP1193Provider),\n\t\tisUserRejection: isEip1193UserRejection,\n\t\t// Drop the cached account observable so a later reconnect rebuilds it\n\t\t// against the current provider, not a stale closure.\n\t\tonDisconnected: (walletId) => clearCachedObservable(`accounts:${walletId}`),\n\t\tbuildWallet: ({\n\t\t\tsource: pd,\n\t\t\twalletId,\n\t\t\tstatus,\n\t\t\terror,\n\t\t\tisConnected,\n\t\t\tconnect,\n\t\t\tdisconnect,\n\t\t}) => ({\n\t\t\tplatform: \"ethereum\",\n\t\t\ttype: \"injected\",\n\t\t\tid: walletId,\n\t\t\tname: pd.info.name,\n\t\t\ticon: pd.info.icon,\n\t\t\tprovider: pd.provider as EIP1193Provider,\n\t\t\tstatus,\n\t\t\terror,\n\t\t\tisConnected,\n\t\t\tsourceId: pd.info.rdns,\n\t\t\tconnect,\n\t\t\tdisconnect,\n\t\t}),\n\t});\n","import type { KheopskitPlatform, PlatformContext } from \"../types\";\nimport { getEthereumAccounts$ } from \"./accounts\";\nimport type { EthereumAccount, EthereumWallet } from \"./types\";\nimport { getEthereumWallets$ } from \"./wallets\";\n\n/**\n * Ethereum platform plugin. Pass to `createKheopskit({ platforms: [ethereum()] })`.\n *\n * @example\n * ```ts\n * import { ethereum } from \"@kheopskit/core/ethereum\";\n * ethereum();\n * ```\n */\nexport const ethereum = (): KheopskitPlatform<\n\t\"ethereum\",\n\tEthereumWallet,\n\tEthereumAccount\n> => ({\n\tplatform: \"ethereum\",\n\tgetWallets$: (ctx: PlatformContext) => getEthereumWallets$(ctx.store),\n\tgetAccounts$: (wallets$) => getEthereumAccounts$(wallets$),\n});\n"],"mappings":";;;;;;;;AAkCA,MAAM,uBAAuB,UAAuC;CACnE,IAAI,MAAM;CAEV,IAAI,OAAO,QAAQ,YAAY,IAAI,WAAW,SAAS,GAC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it/core",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"description": "Framework-agnostic wallet and account discovery for Polkadot, Ethereum and Solana dapps. Upgrading from v5? Read MIGRATING_TO_V6.md, shipped in this package.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|