@kheopskit/core 6.0.0-rc.5 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +112 -0
- package/README.md +11 -0
- package/dist/config-Bb-Zz8J1.d.ts +14 -0
- package/dist/config-Btb40ehu.mjs +29 -0
- package/dist/config-Btb40ehu.mjs.map +1 -0
- package/dist/config-C-Xk2AP_.d.mts +14 -0
- package/dist/config-D1jjip6f.js +52 -0
- package/dist/config-D1jjip6f.js.map +1 -0
- package/dist/errors-BBTNA4Pk.mjs +115 -0
- package/dist/errors-BBTNA4Pk.mjs.map +1 -0
- package/dist/{types-D7OWi0Td.mjs → errors-DVaVewcH.js} +43 -103
- package/dist/errors-DVaVewcH.js.map +1 -0
- package/dist/ethereum.js +5 -4
- package/dist/ethereum.js.map +1 -1
- package/dist/ethereum.mjs +4 -3
- package/dist/ethereum.mjs.map +1 -1
- package/dist/index.d.mts +2 -10
- package/dist/index.d.ts +2 -10
- package/dist/index.js +8 -6
- package/dist/index.mjs +5 -3
- package/dist/{injectedWallets-D7wzBr_f.js → injectedWallets-CeYCeVh5.js} +8 -8
- package/dist/{injectedWallets-D7wzBr_f.js.map → injectedWallets-CeYCeVh5.js.map} +1 -1
- package/dist/{injectedWallets-DHf2lYVb.mjs → injectedWallets-Do5__knh.mjs} +2 -2
- package/dist/{injectedWallets-DHf2lYVb.mjs.map → injectedWallets-Do5__knh.mjs.map} +1 -1
- package/dist/{instance-CCP7uJV3.js → instance-CBN_ifH_.js} +22 -54
- package/dist/instance-CBN_ifH_.js.map +1 -0
- package/dist/{instance-BPAvq0v7.mjs → instance-DmBE3vtX.mjs} +8 -28
- package/dist/instance-DmBE3vtX.mjs.map +1 -0
- package/dist/internal.js +2 -2
- package/dist/internal.mjs +2 -2
- package/dist/{platformAccounts-BeMDbmUT.mjs → platformAccounts-C1sFv82e.mjs} +10 -3
- package/dist/{platformAccounts-BeMDbmUT.mjs.map → platformAccounts-C1sFv82e.mjs.map} +1 -1
- package/dist/{platformAccounts-FE7oA3-Y.js → platformAccounts-CqMSpl3X.js} +10 -3
- package/dist/{platformAccounts-FE7oA3-Y.js.map → platformAccounts-CqMSpl3X.js.map} +1 -1
- package/dist/polkadot.d.mts +13 -0
- package/dist/polkadot.d.ts +13 -0
- package/dist/polkadot.js +22 -16
- package/dist/polkadot.js.map +1 -1
- package/dist/polkadot.mjs +14 -8
- package/dist/polkadot.mjs.map +1 -1
- package/dist/{registryReads-30CCkmHe.js → polkadotExtensions-BoVKhNU_.mjs} +2 -43
- package/dist/polkadotExtensions-BoVKhNU_.mjs.map +1 -0
- package/dist/{registryReads-HvSaXRWX.mjs → polkadotExtensions-y4J9UzYl.js} +5 -30
- package/dist/polkadotExtensions-y4J9UzYl.js.map +1 -0
- package/dist/registryReads-BelydyRc.js +46 -0
- package/dist/registryReads-BelydyRc.js.map +1 -0
- package/dist/registryReads-cdob5BUy.mjs +35 -0
- package/dist/registryReads-cdob5BUy.mjs.map +1 -0
- package/dist/solana.js +9 -8
- package/dist/solana.js.map +1 -1
- package/dist/solana.mjs +4 -3
- package/dist/solana.mjs.map +1 -1
- package/dist/testing.d.mts +6 -1
- package/dist/testing.d.ts +6 -1
- package/dist/testing.js +5 -0
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +3 -1
- package/dist/testing.mjs.map +1 -1
- package/dist/types-DaRMgleZ.js +169 -0
- package/dist/types-DaRMgleZ.js.map +1 -0
- package/dist/types-DcpmEGhO.mjs +104 -0
- package/dist/types-DcpmEGhO.mjs.map +1 -0
- package/dist/walletconnect.js +3 -2
- package/dist/walletconnect.js.map +1 -1
- package/dist/walletconnect.mjs +2 -1
- package/dist/walletconnect.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/instance-BPAvq0v7.mjs.map +0 -1
- package/dist/instance-CCP7uJV3.js.map +0 -1
- package/dist/registryReads-30CCkmHe.js.map +0 -1
- package/dist/registryReads-HvSaXRWX.mjs.map +0 -1
- package/dist/types-BrMtrjs9.js +0 -323
- package/dist/types-BrMtrjs9.js.map +0 -1
- package/dist/types-D7OWi0Td.mjs.map +0 -1
package/dist/ethereum.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_types = require("./types-
|
|
3
|
-
const require_platformAccounts = require("./platformAccounts-
|
|
4
|
-
const
|
|
2
|
+
const require_types = require("./types-DaRMgleZ.js");
|
|
3
|
+
const require_platformAccounts = require("./platformAccounts-CqMSpl3X.js");
|
|
4
|
+
const require_errors = require("./errors-DVaVewcH.js");
|
|
5
|
+
const require_injectedWallets = require("./injectedWallets-CeYCeVh5.js");
|
|
5
6
|
let rxjs = require("rxjs");
|
|
6
7
|
let viem = require("viem");
|
|
7
8
|
let mipd = require("mipd");
|
|
@@ -185,7 +186,7 @@ const getEthereumWallets$ = (store) => require_injectedWallets.createInjectedWal
|
|
|
185
186
|
connect: async (pd) => {
|
|
186
187
|
await pd.provider.request({ method: "eth_requestAccounts" });
|
|
187
188
|
},
|
|
188
|
-
isUserRejection:
|
|
189
|
+
isUserRejection: require_errors.isEip1193UserRejection,
|
|
189
190
|
onDisconnected: (walletId) => require_types.clearCachedObservable(`accounts:${walletId}`),
|
|
190
191
|
buildWallet: ({ source: pd, walletId, status, error, isConnected, connect, disconnect }) => ({
|
|
191
192
|
platform: "ethereum",
|
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 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(\"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(\"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,aA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","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 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(\"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(\"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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ACA;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"}
|
package/dist/ethereum.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { d as getWalletId,
|
|
2
|
-
import { d as isEthereumAddress, i as getSessionCaip10s, o as getWalletAccountId, r as getCaip10Addresses, t as createPlatformAccounts$ } from "./platformAccounts-
|
|
3
|
-
import {
|
|
1
|
+
import { d as getCachedObservable$, i as getWalletId, l as clearCachedObservable, n as isWalletConnectWallet, t as isInjectedWallet } from "./types-DcpmEGhO.mjs";
|
|
2
|
+
import { d as isEthereumAddress, i as getSessionCaip10s, o as getWalletAccountId, r as getCaip10Addresses, t as createPlatformAccounts$ } from "./platformAccounts-C1sFv82e.mjs";
|
|
3
|
+
import { i as isEip1193UserRejection } from "./errors-BBTNA4Pk.mjs";
|
|
4
|
+
import { t as createInjectedWallets$ } from "./injectedWallets-Do5__knh.mjs";
|
|
4
5
|
import { Observable, ReplaySubject, combineLatest, distinctUntilChanged, map, of, shareReplay } from "rxjs";
|
|
5
6
|
import { createWalletClient, custom, getAddress } from "viem";
|
|
6
7
|
import { createStore } from "mipd";
|
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 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(\"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(\"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,OAAO,KAAA;EACxB,MAAM,SAAS,WAAW,WAAW,IAAI,IACtC,OAAO,SAAS,YAAY,EAAE,IAC9B,OAAO,SAAS,YAAY,EAAE;EACjC,OAAO,OAAO,MAAM,MAAM,IAAI,KAAA,IAAY;CAC3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;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\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 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(\"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(\"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,OAAO,KAAA;EACxB,MAAM,SAAS,WAAW,WAAW,IAAI,IACtC,OAAO,SAAS,YAAY,EAAE,IAC9B,OAAO,SAAS,YAAY,EAAE;EACjC,OAAO,OAAO,MAAM,MAAM,IAAI,KAAA,IAAY;CAC3C;AAGD;AAEA,MAAM,mBAAmB,UAAuC;CAC/D,MAAM,UAAU,oBAAoB,KAAK;CACzC,OAAO,YAAY,KAAA,IAAY,KAAA,IAAY,UAAU;AACtD;AAEA,MAAM,8BACL,WACmC;CACnC,IAAI,CAAC,OAAO,aAAa,OAAO,GAAG,CAAC,CAAC;CAErC,OAAO,qBAAqB,YAAY,OAAO,YAC9C,IAAI,YAA+B,eAAe;EACjD,MAAM,aAAa,IAAI,cAAwB,CAAC;EAChD,MAAM,WAAW,IAAI,cAAkC,CAAC;EAExD,MAAM,cACL,SACA,YACqB;GACrB,MAAM,SAAS,mBAAmB;IACjC,SAAS;IACT,WAAW,OAAO,OAAO,QAA2B;GACrD,CAAC;GAED,OAAO;IACN,IAAI,mBAAmB,OAAO,IAAI,OAAO;I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2
2
|
import { A as getWalletId, C as WalletStatus, D as KheopskitError, E as isWalletConnectWallet, F as parseWalletAccountId, M as parseWalletId, N as WalletAccountId, O as KheopskitErrorCode, P as getWalletAccountId, S as WalletPlatform, T as isInjectedWallet, _ as WalletConnectMetadata, a as CachedAccount, b as WalletConnectWallet, c as KheopskitConfig, d as KheopskitStore, f as KheopskitStoreData, g as PolkadotAccountType, h as PlatformContext, i as BaseWalletAccount, j as isValidWalletId, k as WalletId, l as KheopskitPlatform, m as PlaceholderWallet, n as AppKitInstance, o as CachedWallet, p as Placeholder, r as BaseWallet, s as ConnectOptions, t as AccountOf, u as KheopskitState, v as WalletConnectPlugin, w as WalletType, x as WalletOf, y as WalletConnectProvider } from "./types-BGeGUtxz.mjs";
|
|
3
3
|
import { a as createKheopskit, c as clearAllCachedObservables, n as CreateKheopskitOptions, r as Kheopskit, t as CreateKheopskitConfig } from "./instance-DDvZiq1L.mjs";
|
|
4
|
+
import { i as resolveConfig, r as DEFAULT_STORAGE_KEY } from "./config-C-Xk2AP_.mjs";
|
|
4
5
|
//#region src/utils/isValidAddress.d.ts
|
|
5
6
|
export declare const isValidAddress: (address: string) => boolean;
|
|
6
7
|
//#endregion
|
|
7
|
-
//#region src/api/config.d.ts
|
|
8
|
-
/**
|
|
9
|
-
* Default storage key for persisting wallet connection state.
|
|
10
|
-
* Can be overridden via config.storageKey to avoid conflicts
|
|
11
|
-
* when running multiple dapps on the same domain.
|
|
12
|
-
*/
|
|
13
|
-
export declare const DEFAULT_STORAGE_KEY = "kheopskit";
|
|
14
|
-
export declare const resolveConfig: <const P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]>(config?: Partial<KheopskitConfig<P>>) => KheopskitConfig<P>;
|
|
15
|
-
//#endregion
|
|
16
8
|
//#region src/api/store.d.ts
|
|
17
9
|
type CreateKheopskitStoreOptions = {
|
|
18
10
|
/**
|
|
@@ -80,5 +72,5 @@ type GetHydratedSnapshotOptions = {
|
|
|
80
72
|
*/
|
|
81
73
|
export declare const getHydratedSnapshot: (store: KheopskitStore, config: Pick<KheopskitConfig, "platforms" | "autoReconnect" | "walletConnect">, options?: GetHydratedSnapshotOptions) => HydratedSnapshot;
|
|
82
74
|
//#endregion
|
|
83
|
-
export { AccountOf, AppKitInstance, BaseWallet, BaseWalletAccount, CachedAccount, CachedWallet, ConnectOptions, type CreateKheopskitConfig, type CreateKheopskitOptions, type GetHydratedSnapshotOptions, type HydratedSnapshot, type Kheopskit, KheopskitConfig, KheopskitError, type KheopskitErrorCode, KheopskitPlatform, KheopskitState, KheopskitStore, KheopskitStoreData, Placeholder, PlaceholderWallet, PlatformContext, PolkadotAccountType, type SyncableStorage, type WalletAccountId, WalletConnectMetadata, WalletConnectPlugin, WalletConnectProvider, WalletConnectWallet, type WalletId, WalletOf, WalletPlatform, WalletStatus, WalletType, clearAllCachedObservables, createKheopskit, getWalletAccountId, getWalletId, isInjectedWallet, isValidWalletId, isWalletConnectWallet, parseWalletAccountId, parseWalletId };
|
|
75
|
+
export { AccountOf, AppKitInstance, BaseWallet, BaseWalletAccount, CachedAccount, CachedWallet, ConnectOptions, type CreateKheopskitConfig, type CreateKheopskitOptions, DEFAULT_STORAGE_KEY, type GetHydratedSnapshotOptions, type HydratedSnapshot, type Kheopskit, KheopskitConfig, KheopskitError, type KheopskitErrorCode, KheopskitPlatform, KheopskitState, KheopskitStore, KheopskitStoreData, Placeholder, PlaceholderWallet, PlatformContext, PolkadotAccountType, type SyncableStorage, type WalletAccountId, WalletConnectMetadata, WalletConnectPlugin, WalletConnectProvider, WalletConnectWallet, type WalletId, WalletOf, WalletPlatform, WalletStatus, WalletType, clearAllCachedObservables, createKheopskit, getWalletAccountId, getWalletId, isInjectedWallet, isValidWalletId, isWalletConnectWallet, parseWalletAccountId, parseWalletId, resolveConfig };
|
|
84
76
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { t as SyncableStorage } from "./storage-D3AwNgqc.js";
|
|
2
2
|
import { A as getWalletId, C as WalletStatus, D as KheopskitError, E as isWalletConnectWallet, F as parseWalletAccountId, M as parseWalletId, N as WalletAccountId, O as KheopskitErrorCode, P as getWalletAccountId, S as WalletPlatform, T as isInjectedWallet, _ as WalletConnectMetadata, a as CachedAccount, b as WalletConnectWallet, c as KheopskitConfig, d as KheopskitStore, f as KheopskitStoreData, g as PolkadotAccountType, h as PlatformContext, i as BaseWalletAccount, j as isValidWalletId, k as WalletId, l as KheopskitPlatform, m as PlaceholderWallet, n as AppKitInstance, o as CachedWallet, p as Placeholder, r as BaseWallet, s as ConnectOptions, t as AccountOf, u as KheopskitState, v as WalletConnectPlugin, w as WalletType, x as WalletOf, y as WalletConnectProvider } from "./types-BGeGUtxz.js";
|
|
3
3
|
import { a as createKheopskit, c as clearAllCachedObservables, n as CreateKheopskitOptions, r as Kheopskit, t as CreateKheopskitConfig } from "./instance-1BgEld17.js";
|
|
4
|
+
import { i as resolveConfig, r as DEFAULT_STORAGE_KEY } from "./config-Bb-Zz8J1.js";
|
|
4
5
|
//#region src/utils/isValidAddress.d.ts
|
|
5
6
|
export declare const isValidAddress: (address: string) => boolean;
|
|
6
7
|
//#endregion
|
|
7
|
-
//#region src/api/config.d.ts
|
|
8
|
-
/**
|
|
9
|
-
* Default storage key for persisting wallet connection state.
|
|
10
|
-
* Can be overridden via config.storageKey to avoid conflicts
|
|
11
|
-
* when running multiple dapps on the same domain.
|
|
12
|
-
*/
|
|
13
|
-
export declare const DEFAULT_STORAGE_KEY = "kheopskit";
|
|
14
|
-
export declare const resolveConfig: <const P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]>(config?: Partial<KheopskitConfig<P>>) => KheopskitConfig<P>;
|
|
15
|
-
//#endregion
|
|
16
8
|
//#region src/api/store.d.ts
|
|
17
9
|
type CreateKheopskitStoreOptions = {
|
|
18
10
|
/**
|
|
@@ -80,5 +72,5 @@ type GetHydratedSnapshotOptions = {
|
|
|
80
72
|
*/
|
|
81
73
|
export declare const getHydratedSnapshot: (store: KheopskitStore, config: Pick<KheopskitConfig, "platforms" | "autoReconnect" | "walletConnect">, options?: GetHydratedSnapshotOptions) => HydratedSnapshot;
|
|
82
74
|
//#endregion
|
|
83
|
-
export { AccountOf, AppKitInstance, BaseWallet, BaseWalletAccount, CachedAccount, CachedWallet, ConnectOptions, type CreateKheopskitConfig, type CreateKheopskitOptions, type GetHydratedSnapshotOptions, type HydratedSnapshot, type Kheopskit, KheopskitConfig, KheopskitError, type KheopskitErrorCode, KheopskitPlatform, KheopskitState, KheopskitStore, KheopskitStoreData, Placeholder, PlaceholderWallet, PlatformContext, PolkadotAccountType, type SyncableStorage, type WalletAccountId, WalletConnectMetadata, WalletConnectPlugin, WalletConnectProvider, WalletConnectWallet, type WalletId, WalletOf, WalletPlatform, WalletStatus, WalletType, clearAllCachedObservables, createKheopskit, getWalletAccountId, getWalletId, isInjectedWallet, isValidWalletId, isWalletConnectWallet, parseWalletAccountId, parseWalletId };
|
|
75
|
+
export { AccountOf, AppKitInstance, BaseWallet, BaseWalletAccount, CachedAccount, CachedWallet, ConnectOptions, type CreateKheopskitConfig, type CreateKheopskitOptions, DEFAULT_STORAGE_KEY, type GetHydratedSnapshotOptions, type HydratedSnapshot, type Kheopskit, KheopskitConfig, KheopskitError, type KheopskitErrorCode, KheopskitPlatform, KheopskitState, KheopskitStore, KheopskitStoreData, Placeholder, PlaceholderWallet, PlatformContext, PolkadotAccountType, type SyncableStorage, type WalletAccountId, WalletConnectMetadata, WalletConnectPlugin, WalletConnectProvider, WalletConnectWallet, type WalletId, WalletOf, WalletPlatform, WalletStatus, WalletType, clearAllCachedObservables, createKheopskit, getWalletAccountId, getWalletId, isInjectedWallet, isValidWalletId, isWalletConnectWallet, parseWalletAccountId, parseWalletId, resolveConfig };
|
|
84
76
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_types = require("./types-
|
|
3
|
-
const require_platformAccounts = require("./platformAccounts-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
const require_types = require("./types-DaRMgleZ.js");
|
|
3
|
+
const require_platformAccounts = require("./platformAccounts-CqMSpl3X.js");
|
|
4
|
+
const require_errors = require("./errors-DVaVewcH.js");
|
|
5
|
+
const require_config = require("./config-D1jjip6f.js");
|
|
6
|
+
const require_instance = require("./instance-CBN_ifH_.js");
|
|
7
|
+
exports.DEFAULT_STORAGE_KEY = require_config.DEFAULT_STORAGE_KEY;
|
|
8
|
+
exports.KheopskitError = require_errors.KheopskitError;
|
|
7
9
|
exports.clearAllCachedObservables = require_types.clearAllCachedObservables;
|
|
8
10
|
exports.createKheopskit = require_instance.createKheopskit;
|
|
9
11
|
exports.createKheopskitStore = require_instance.createKheopskitStore;
|
|
@@ -17,4 +19,4 @@ exports.isValidWalletId = require_types.isValidWalletId;
|
|
|
17
19
|
exports.isWalletConnectWallet = require_types.isWalletConnectWallet;
|
|
18
20
|
exports.parseWalletAccountId = require_platformAccounts.parseWalletAccountId;
|
|
19
21
|
exports.parseWalletId = require_types.parseWalletId;
|
|
20
|
-
exports.resolveConfig =
|
|
22
|
+
exports.resolveConfig = require_config.resolveConfig;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as isValidAddress, o as getWalletAccountId, s as parseWalletAccountId } from "./platformAccounts-
|
|
3
|
-
import {
|
|
1
|
+
import { a as isValidWalletId, c as clearAllCachedObservables, i as getWalletId, n as isWalletConnectWallet, o as parseWalletId, t as isInjectedWallet } from "./types-DcpmEGhO.mjs";
|
|
2
|
+
import { c as isValidAddress, o as getWalletAccountId, s as parseWalletAccountId } from "./platformAccounts-C1sFv82e.mjs";
|
|
3
|
+
import { t as KheopskitError } from "./errors-BBTNA4Pk.mjs";
|
|
4
|
+
import { i as resolveConfig, r as DEFAULT_STORAGE_KEY } from "./config-Btb40ehu.mjs";
|
|
5
|
+
import { a as getDefaultStore, i as createKheopskitStore, n as createKheopskit, o as getHydratedSnapshot } from "./instance-DmBE3vtX.mjs";
|
|
4
6
|
export { DEFAULT_STORAGE_KEY, KheopskitError, clearAllCachedObservables, createKheopskit, createKheopskitStore, getDefaultStore, getHydratedSnapshot, getWalletAccountId, getWalletId, isInjectedWallet, isValidAddress, isValidWalletId, isWalletConnectWallet, parseWalletAccountId, parseWalletId, resolveConfig };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_errors = require("./errors-DVaVewcH.js");
|
|
2
2
|
let rxjs = require("rxjs");
|
|
3
3
|
//#region src/api/injectedWallets.ts
|
|
4
4
|
/**
|
|
@@ -18,7 +18,7 @@ const join = (connecting, walletId, signal) => {
|
|
|
18
18
|
return new Promise((resolve, reject) => {
|
|
19
19
|
const leave = () => {
|
|
20
20
|
if (connecting.answered) return;
|
|
21
|
-
reject(
|
|
21
|
+
reject(require_errors.abortedError(walletId, "connect"));
|
|
22
22
|
connecting.waiting--;
|
|
23
23
|
if (!connecting.anchored && connecting.waiting === 0) connecting.abort();
|
|
24
24
|
};
|
|
@@ -54,7 +54,7 @@ const createInjectedWallets$ = (store, adapter) => new rxjs.Observable((subscrib
|
|
|
54
54
|
promise: new Promise((resolve, reject) => {
|
|
55
55
|
controller.signal.addEventListener("abort", () => {
|
|
56
56
|
setConnection(walletId, void 0);
|
|
57
|
-
reject(
|
|
57
|
+
reject(require_errors.abortedError(walletId, "connect"));
|
|
58
58
|
}, { once: true });
|
|
59
59
|
new Promise((res) => res(adapter.connect(source, walletId))).then((handle) => {
|
|
60
60
|
connecting.answered = true;
|
|
@@ -71,7 +71,7 @@ const createInjectedWallets$ = (store, adapter) => new rxjs.Observable((subscrib
|
|
|
71
71
|
}, (error) => {
|
|
72
72
|
connecting.answered = true;
|
|
73
73
|
if (controller.signal.aborted) return;
|
|
74
|
-
const connectError =
|
|
74
|
+
const connectError = require_errors.toConnectError(error, walletId, adapter.isUserRejection ?? (() => false));
|
|
75
75
|
setConnection(walletId, {
|
|
76
76
|
status: "disconnected",
|
|
77
77
|
error: connectError
|
|
@@ -93,7 +93,7 @@ const createInjectedWallets$ = (store, adapter) => new rxjs.Observable((subscrib
|
|
|
93
93
|
const signals = signal ? [teardown.signal, signal] : [teardown.signal];
|
|
94
94
|
const settle = () => {
|
|
95
95
|
for (const s of signals) s.removeEventListener("abort", settle);
|
|
96
|
-
if (signals.some((s) => s.aborted)) reject(
|
|
96
|
+
if (signals.some((s) => s.aborted)) reject(require_errors.abortedError(walletId, "connect"));
|
|
97
97
|
else resolve();
|
|
98
98
|
};
|
|
99
99
|
if (signals.some((s) => s.aborted)) return settle();
|
|
@@ -101,13 +101,13 @@ const createInjectedWallets$ = (store, adapter) => new rxjs.Observable((subscrib
|
|
|
101
101
|
disconnecting.then(settle, settle);
|
|
102
102
|
});
|
|
103
103
|
const connect = (source, walletId, options) => {
|
|
104
|
-
if (teardown.signal.aborted || !present.has(walletId)) return Promise.reject(
|
|
104
|
+
if (teardown.signal.aborted || !present.has(walletId)) return Promise.reject(require_errors.abortedError(walletId, "connect"));
|
|
105
105
|
const current = connections$.value.get(walletId);
|
|
106
106
|
if (current?.status === "connected") {
|
|
107
107
|
if (!current.disconnecting) return Promise.resolve();
|
|
108
108
|
return untilSettled(current.disconnecting, walletId, options?.signal).then(() => connect(source, walletId, options));
|
|
109
109
|
}
|
|
110
|
-
if (options?.signal?.aborted) return Promise.reject(
|
|
110
|
+
if (options?.signal?.aborted) return Promise.reject(require_errors.abortedError(walletId, "connect"));
|
|
111
111
|
if (current?.status === "connecting") return join(current, walletId, options?.signal);
|
|
112
112
|
return startConnect(source, walletId, options?.signal);
|
|
113
113
|
};
|
|
@@ -175,4 +175,4 @@ Object.defineProperty(exports, "createInjectedWallets$", {
|
|
|
175
175
|
}
|
|
176
176
|
});
|
|
177
177
|
|
|
178
|
-
//# sourceMappingURL=injectedWallets-
|
|
178
|
+
//# sourceMappingURL=injectedWallets-CeYCeVh5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectedWallets-D7wzBr_f.js","names":["abortedError","Observable","BehaviorSubject","toConnectError","combineLatest","tap","map","distinctUntilChanged","shareReplay"],"sources":["../src/api/injectedWallets.ts"],"sourcesContent":["import {\n\tBehaviorSubject,\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tshareReplay,\n\ttap,\n} from \"rxjs\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport { abortedError, type KheopskitError, toConnectError } from \"./errors\";\nimport type { KheopskitStore } from \"./store\";\nimport type { BaseWallet, ConnectOptions, WalletStatus } 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\" | \"status\" | \"error\" | \"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.status === b[i]?.status &&\n\t\t\tw.error === b[i]?.error &&\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 */\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. The resolved value is retained as the wallet's\n\t * live handle until disconnect.\n\t */\n\tconnect: (source: TSource, walletId: WalletId) => Promise<THandle>;\n\t/** `true` maps the platform's rejection to `USER_REJECTED`; absent means never. */\n\tisUserRejection?: (error: unknown) => boolean;\n\treleaseAbandonedHandle?: (handle: THandle, walletId: WalletId) => void;\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\tstatus: WalletStatus;\n\t\terror: KheopskitError | undefined;\n\t\tisConnected: boolean;\n\t\tconnect: (options?: ConnectOptions) => Promise<void>;\n\t\tdisconnect: () => Promise<void>;\n\t}) => TWallet;\n};\n\ntype Connecting = {\n\tstatus: \"connecting\";\n\tpromise: Promise<void>;\n\tanchored: boolean;\n\twaiting: number;\n\tanswered: boolean;\n\tabort: () => void;\n};\n\ntype Connection<THandle> =\n\t| Connecting\n\t| { status: \"connected\"; handle: THandle; disconnecting?: Promise<void> }\n\t| { status: \"disconnected\"; error: KheopskitError };\n\nconst join = (\n\tconnecting: Connecting,\n\twalletId: WalletId,\n\tsignal: AbortSignal | undefined,\n): Promise<void> => {\n\tif (!signal) {\n\t\tconnecting.anchored = true;\n\t\treturn connecting.promise;\n\t}\n\tconnecting.waiting++;\n\treturn new Promise<void>((resolve, reject) => {\n\t\tconst leave = () => {\n\t\t\tif (connecting.answered) return;\n\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\tconnecting.waiting--;\n\t\t\tif (!connecting.anchored && connecting.waiting === 0) connecting.abort();\n\t\t};\n\t\tsignal.addEventListener(\"abort\", leave, { once: true });\n\t\tconnecting.promise\n\t\t\t.then(resolve, reject)\n\t\t\t.finally(() => signal.removeEventListener(\"abort\", leave));\n\t});\n};\n\n/**\n * The shared engine behind every platform's injected-wallets stream: tracks\n * each wallet's connection (pending attempt or live handle), shares one\n * in-flight connect per wallet, persists connected ids to the store for\n * auto-reconnect, and re-emits the wallet list whenever the registry or\n * connection state 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 connections$ = new BehaviorSubject<\n\t\t\tReadonlyMap<WalletId, Connection<THandle>>\n\t\t>(new Map());\n\t\tconst teardown = new AbortController();\n\t\tlet present = new Set<WalletId>();\n\n\t\tconst abortConnectsOfSourcesThatLeft = (sources: readonly TSource[]) => {\n\t\t\tpresent = new Set(sources.map((source) => adapter.getWalletId(source)));\n\t\t\tfor (const [walletId, connection] of connections$.value)\n\t\t\t\tif (connection.status === \"connecting\" && !present.has(walletId))\n\t\t\t\t\tconnection.abort();\n\t\t};\n\n\t\tconst setConnection = (\n\t\t\twalletId: WalletId,\n\t\t\tconnection: Connection<THandle> | undefined,\n\t\t) => {\n\t\t\tconst next = new Map(connections$.value);\n\t\t\tif (connection) next.set(walletId, connection);\n\t\t\telse next.delete(walletId);\n\t\t\tconnections$.next(next);\n\t\t};\n\n\t\tconst startConnect = (\n\t\t\tsource: TSource,\n\t\t\twalletId: WalletId,\n\t\t\tsignal: AbortSignal | undefined,\n\t\t): Promise<void> => {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst promise = new Promise<void>((resolve, reject) => {\n\t\t\t\tcontroller.signal.addEventListener(\n\t\t\t\t\t\"abort\",\n\t\t\t\t\t() => {\n\t\t\t\t\t\tsetConnection(walletId, undefined);\n\t\t\t\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\t\t\t},\n\t\t\t\t\t{ once: true },\n\t\t\t\t);\n\t\t\t\tnew Promise<THandle>((res) =>\n\t\t\t\t\tres(adapter.connect(source, walletId)),\n\t\t\t\t).then(\n\t\t\t\t\t(handle) => {\n\t\t\t\t\t\tconnecting.answered = true;\n\t\t\t\t\t\tif (controller.signal.aborted) {\n\t\t\t\t\t\t\tadapter.releaseAbandonedHandle?.(handle, walletId);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsetConnection(walletId, { status: \"connected\", handle });\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t\tstore.rememberWallet(walletId);\n\t\t\t\t\t},\n\t\t\t\t\t(error) => {\n\t\t\t\t\t\tconnecting.answered = true;\n\t\t\t\t\t\tif (controller.signal.aborted) return;\n\t\t\t\t\t\tconst connectError = toConnectError(\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\twalletId,\n\t\t\t\t\t\t\tadapter.isUserRejection ?? (() => false),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tsetConnection(walletId, {\n\t\t\t\t\t\t\tstatus: \"disconnected\",\n\t\t\t\t\t\t\terror: connectError,\n\t\t\t\t\t\t});\n\t\t\t\t\t\treject(connectError);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t\tconst connecting: Connecting = {\n\t\t\t\tstatus: \"connecting\",\n\t\t\t\tpromise,\n\t\t\t\tanchored: false,\n\t\t\t\twaiting: 0,\n\t\t\t\tanswered: false,\n\t\t\t\tabort: () => {\n\t\t\t\t\tif (connections$.value.get(walletId) === connecting)\n\t\t\t\t\t\tcontroller.abort();\n\t\t\t\t},\n\t\t\t};\n\t\t\tsetConnection(walletId, connecting);\n\t\t\treturn join(connecting, walletId, signal);\n\t\t};\n\n\t\tconst untilSettled = (\n\t\t\tdisconnecting: Promise<void>,\n\t\t\twalletId: WalletId,\n\t\t\tsignal: AbortSignal | undefined,\n\t\t): Promise<void> =>\n\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\tconst signals = signal ? [teardown.signal, signal] : [teardown.signal];\n\t\t\t\tconst settle = () => {\n\t\t\t\t\tfor (const s of signals) s.removeEventListener(\"abort\", settle);\n\t\t\t\t\tif (signals.some((s) => s.aborted))\n\t\t\t\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\t\t\telse resolve();\n\t\t\t\t};\n\t\t\t\tif (signals.some((s) => s.aborted)) return settle();\n\t\t\t\tfor (const s of signals)\n\t\t\t\t\ts.addEventListener(\"abort\", settle, { once: true });\n\t\t\t\tdisconnecting.then(settle, settle);\n\t\t\t});\n\n\t\tconst connect = (\n\t\t\tsource: TSource,\n\t\t\twalletId: WalletId,\n\t\t\toptions?: ConnectOptions,\n\t\t): Promise<void> => {\n\t\t\tif (teardown.signal.aborted || !present.has(walletId))\n\t\t\t\treturn Promise.reject(abortedError(walletId, \"connect\"));\n\t\t\tconst current = connections$.value.get(walletId);\n\t\t\tif (current?.status === \"connected\") {\n\t\t\t\tif (!current.disconnecting) return Promise.resolve();\n\t\t\t\treturn untilSettled(\n\t\t\t\t\tcurrent.disconnecting,\n\t\t\t\t\twalletId,\n\t\t\t\t\toptions?.signal,\n\t\t\t\t).then(() => connect(source, walletId, options));\n\t\t\t}\n\t\t\tif (options?.signal?.aborted)\n\t\t\t\treturn Promise.reject(abortedError(walletId, \"connect\"));\n\t\t\tif (current?.status === \"connecting\")\n\t\t\t\treturn join(current, walletId, options?.signal);\n\t\t\treturn startConnect(source, walletId, options?.signal);\n\t\t};\n\n\t\tconst disconnect = (source: TSource, walletId: WalletId): Promise<void> => {\n\t\t\tconst current = connections$.value.get(walletId);\n\t\t\tstore.forgetWallet(walletId);\n\t\t\tif (!current || current.status === \"disconnected\")\n\t\t\t\treturn Promise.resolve();\n\t\t\tif (current.status === \"connecting\") {\n\t\t\t\tcurrent.abort();\n\t\t\t\treturn Promise.resolve();\n\t\t\t}\n\t\t\tif (current.disconnecting) return current.disconnecting;\n\n\t\t\tconst disconnecting = (async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait adapter.disconnect?.(source, walletId);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!teardown.signal.aborted) {\n\t\t\t\t\t\tsetConnection(walletId, {\n\t\t\t\t\t\t\tstatus: \"connected\",\n\t\t\t\t\t\t\thandle: current.handle,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tstore.rememberWallet(walletId);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tif (teardown.signal.aborted) return;\n\t\t\t\tsetConnection(walletId, undefined);\n\t\t\t\tadapter.onDisconnected?.(walletId);\n\t\t\t})();\n\t\t\tsetConnection(walletId, { ...current, disconnecting });\n\t\t\treturn disconnecting;\n\t\t};\n\n\t\tconst sub = combineLatest([adapter.sources$, connections$])\n\t\t\t.pipe(\n\t\t\t\ttap(([sources]) => abortConnectsOfSourcesThatLeft(sources)),\n\t\t\t\tmap(([sources, connections]) =>\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\tconst connection = connections.get(walletId);\n\t\t\t\t\t\tconst connected =\n\t\t\t\t\t\t\tconnection?.status === \"connected\" ? connection : undefined;\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: connected?.handle,\n\t\t\t\t\t\t\tstatus: connection?.status ?? \"disconnected\",\n\t\t\t\t\t\t\terror:\n\t\t\t\t\t\t\t\tconnection?.status === \"disconnected\"\n\t\t\t\t\t\t\t\t\t? connection.error\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\tisConnected: connected !== undefined,\n\t\t\t\t\t\t\tconnect: (options) => connect(source, walletId, options),\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\tteardown.abort();\n\t\t\tfor (const connection of connections$.value.values())\n\t\t\t\tif (connection.status === \"connecting\") connection.abort();\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n"],"mappings":";;;;;;;AAkBA,MAAM,gBAGL,GACA,MACa;CACb,IAAI,EAAE,WAAW,EAAE,QAAQ,OAAO;CAClC,OAAO,EAAE,OACP,GAAG,MACH,EAAE,OAAO,EAAE,EAAE,EAAE,MACf,EAAE,WAAW,EAAE,EAAE,EAAE,UACnB,EAAE,UAAU,EAAE,EAAE,EAAE,SAClB,EAAE,SAAS,EAAE,EAAE,EAAE,IACnB;AACD;AAmEA,MAAM,QACL,YACA,UACA,WACmB;CACnB,IAAI,CAAC,QAAQ;EACZ,WAAW,WAAW;EACtB,OAAO,WAAW;CACnB;CACA,WAAW;CACX,OAAO,IAAI,SAAe,SAAS,WAAW;EAC7C,MAAM,cAAc;GACnB,IAAI,WAAW,UAAU;GACzB,OAAOA,cAAAA,aAAa,UAAU,SAAS,CAAC;GACxC,WAAW;GACX,IAAI,CAAC,WAAW,YAAY,WAAW,YAAY,GAAG,WAAW,MAAM;EACxE;EACA,OAAO,iBAAiB,SAAS,OAAO,EAAE,MAAM,KAAK,CAAC;EACtD,WAAW,QACT,KAAK,SAAS,MAAM,CAAC,CACrB,cAAc,OAAO,oBAAoB,SAAS,KAAK,CAAC;CAC3D,CAAC;AACF;;;;;;;;AASA,MAAa,0BAKZ,OACA,YAEA,IAAIC,KAAAA,YAAuB,eAAe;CACzC,MAAM,eAAe,IAAIC,KAAAA,gCAEvB,IAAI,IAAI,CAAC;CACX,MAAM,WAAW,IAAI,gBAAgB;CACrC,IAAI,0BAAU,IAAI,IAAc;CAEhC,MAAM,kCAAkC,YAAgC;EACvE,UAAU,IAAI,IAAI,QAAQ,KA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AA,CAAqB,YAAY,CAClC,CAAC,CACA,UAAU,UAAU;CAEtB,aAAa;EACZ,SAAS,MAAM;EACf,KAAK,MAAM,cAAc,aAAa,MAAM,OAAO,GAClD,IAAI,WAAW,WAAW,cAAc,WAAW,MAAM;EAC1D,IAAI,YAAY;CACjB;AACD,CAAC,CAAC,CAAC,MAAA,GAAKC,KAAAA,YAAAA,CAAY;CAAE,UAAU;CAAM,YAAY;AAAE,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"injectedWallets-CeYCeVh5.js","names":["abortedError","Observable","BehaviorSubject","toConnectError","combineLatest","tap","map","distinctUntilChanged","shareReplay"],"sources":["../src/api/injectedWallets.ts"],"sourcesContent":["import {\n\tBehaviorSubject,\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tshareReplay,\n\ttap,\n} from \"rxjs\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport { abortedError, type KheopskitError, toConnectError } from \"./errors\";\nimport type { KheopskitStore } from \"./store\";\nimport type { BaseWallet, ConnectOptions, WalletStatus } 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\" | \"status\" | \"error\" | \"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.status === b[i]?.status &&\n\t\t\tw.error === b[i]?.error &&\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 */\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. The resolved value is retained as the wallet's\n\t * live handle until disconnect.\n\t */\n\tconnect: (source: TSource, walletId: WalletId) => Promise<THandle>;\n\t/** `true` maps the platform's rejection to `USER_REJECTED`; absent means never. */\n\tisUserRejection?: (error: unknown) => boolean;\n\treleaseAbandonedHandle?: (handle: THandle, walletId: WalletId) => void;\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\tstatus: WalletStatus;\n\t\terror: KheopskitError | undefined;\n\t\tisConnected: boolean;\n\t\tconnect: (options?: ConnectOptions) => Promise<void>;\n\t\tdisconnect: () => Promise<void>;\n\t}) => TWallet;\n};\n\ntype Connecting = {\n\tstatus: \"connecting\";\n\tpromise: Promise<void>;\n\tanchored: boolean;\n\twaiting: number;\n\tanswered: boolean;\n\tabort: () => void;\n};\n\ntype Connection<THandle> =\n\t| Connecting\n\t| { status: \"connected\"; handle: THandle; disconnecting?: Promise<void> }\n\t| { status: \"disconnected\"; error: KheopskitError };\n\nconst join = (\n\tconnecting: Connecting,\n\twalletId: WalletId,\n\tsignal: AbortSignal | undefined,\n): Promise<void> => {\n\tif (!signal) {\n\t\tconnecting.anchored = true;\n\t\treturn connecting.promise;\n\t}\n\tconnecting.waiting++;\n\treturn new Promise<void>((resolve, reject) => {\n\t\tconst leave = () => {\n\t\t\tif (connecting.answered) return;\n\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\tconnecting.waiting--;\n\t\t\tif (!connecting.anchored && connecting.waiting === 0) connecting.abort();\n\t\t};\n\t\tsignal.addEventListener(\"abort\", leave, { once: true });\n\t\tconnecting.promise\n\t\t\t.then(resolve, reject)\n\t\t\t.finally(() => signal.removeEventListener(\"abort\", leave));\n\t});\n};\n\n/**\n * The shared engine behind every platform's injected-wallets stream: tracks\n * each wallet's connection (pending attempt or live handle), shares one\n * in-flight connect per wallet, persists connected ids to the store for\n * auto-reconnect, and re-emits the wallet list whenever the registry or\n * connection state 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 connections$ = new BehaviorSubject<\n\t\t\tReadonlyMap<WalletId, Connection<THandle>>\n\t\t>(new Map());\n\t\tconst teardown = new AbortController();\n\t\tlet present = new Set<WalletId>();\n\n\t\tconst abortConnectsOfSourcesThatLeft = (sources: readonly TSource[]) => {\n\t\t\tpresent = new Set(sources.map((source) => adapter.getWalletId(source)));\n\t\t\tfor (const [walletId, connection] of connections$.value)\n\t\t\t\tif (connection.status === \"connecting\" && !present.has(walletId))\n\t\t\t\t\tconnection.abort();\n\t\t};\n\n\t\tconst setConnection = (\n\t\t\twalletId: WalletId,\n\t\t\tconnection: Connection<THandle> | undefined,\n\t\t) => {\n\t\t\tconst next = new Map(connections$.value);\n\t\t\tif (connection) next.set(walletId, connection);\n\t\t\telse next.delete(walletId);\n\t\t\tconnections$.next(next);\n\t\t};\n\n\t\tconst startConnect = (\n\t\t\tsource: TSource,\n\t\t\twalletId: WalletId,\n\t\t\tsignal: AbortSignal | undefined,\n\t\t): Promise<void> => {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst promise = new Promise<void>((resolve, reject) => {\n\t\t\t\tcontroller.signal.addEventListener(\n\t\t\t\t\t\"abort\",\n\t\t\t\t\t() => {\n\t\t\t\t\t\tsetConnection(walletId, undefined);\n\t\t\t\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\t\t\t},\n\t\t\t\t\t{ once: true },\n\t\t\t\t);\n\t\t\t\tnew Promise<THandle>((res) =>\n\t\t\t\t\tres(adapter.connect(source, walletId)),\n\t\t\t\t).then(\n\t\t\t\t\t(handle) => {\n\t\t\t\t\t\tconnecting.answered = true;\n\t\t\t\t\t\tif (controller.signal.aborted) {\n\t\t\t\t\t\t\tadapter.releaseAbandonedHandle?.(handle, walletId);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsetConnection(walletId, { status: \"connected\", handle });\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t\tstore.rememberWallet(walletId);\n\t\t\t\t\t},\n\t\t\t\t\t(error) => {\n\t\t\t\t\t\tconnecting.answered = true;\n\t\t\t\t\t\tif (controller.signal.aborted) return;\n\t\t\t\t\t\tconst connectError = toConnectError(\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\twalletId,\n\t\t\t\t\t\t\tadapter.isUserRejection ?? (() => false),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tsetConnection(walletId, {\n\t\t\t\t\t\t\tstatus: \"disconnected\",\n\t\t\t\t\t\t\terror: connectError,\n\t\t\t\t\t\t});\n\t\t\t\t\t\treject(connectError);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t\tconst connecting: Connecting = {\n\t\t\t\tstatus: \"connecting\",\n\t\t\t\tpromise,\n\t\t\t\tanchored: false,\n\t\t\t\twaiting: 0,\n\t\t\t\tanswered: false,\n\t\t\t\tabort: () => {\n\t\t\t\t\tif (connections$.value.get(walletId) === connecting)\n\t\t\t\t\t\tcontroller.abort();\n\t\t\t\t},\n\t\t\t};\n\t\t\tsetConnection(walletId, connecting);\n\t\t\treturn join(connecting, walletId, signal);\n\t\t};\n\n\t\tconst untilSettled = (\n\t\t\tdisconnecting: Promise<void>,\n\t\t\twalletId: WalletId,\n\t\t\tsignal: AbortSignal | undefined,\n\t\t): Promise<void> =>\n\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\tconst signals = signal ? [teardown.signal, signal] : [teardown.signal];\n\t\t\t\tconst settle = () => {\n\t\t\t\t\tfor (const s of signals) s.removeEventListener(\"abort\", settle);\n\t\t\t\t\tif (signals.some((s) => s.aborted))\n\t\t\t\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\t\t\telse resolve();\n\t\t\t\t};\n\t\t\t\tif (signals.some((s) => s.aborted)) return settle();\n\t\t\t\tfor (const s of signals)\n\t\t\t\t\ts.addEventListener(\"abort\", settle, { once: true });\n\t\t\t\tdisconnecting.then(settle, settle);\n\t\t\t});\n\n\t\tconst connect = (\n\t\t\tsource: TSource,\n\t\t\twalletId: WalletId,\n\t\t\toptions?: ConnectOptions,\n\t\t): Promise<void> => {\n\t\t\tif (teardown.signal.aborted || !present.has(walletId))\n\t\t\t\treturn Promise.reject(abortedError(walletId, \"connect\"));\n\t\t\tconst current = connections$.value.get(walletId);\n\t\t\tif (current?.status === \"connected\") {\n\t\t\t\tif (!current.disconnecting) return Promise.resolve();\n\t\t\t\treturn untilSettled(\n\t\t\t\t\tcurrent.disconnecting,\n\t\t\t\t\twalletId,\n\t\t\t\t\toptions?.signal,\n\t\t\t\t).then(() => connect(source, walletId, options));\n\t\t\t}\n\t\t\tif (options?.signal?.aborted)\n\t\t\t\treturn Promise.reject(abortedError(walletId, \"connect\"));\n\t\t\tif (current?.status === \"connecting\")\n\t\t\t\treturn join(current, walletId, options?.signal);\n\t\t\treturn startConnect(source, walletId, options?.signal);\n\t\t};\n\n\t\tconst disconnect = (source: TSource, walletId: WalletId): Promise<void> => {\n\t\t\tconst current = connections$.value.get(walletId);\n\t\t\tstore.forgetWallet(walletId);\n\t\t\tif (!current || current.status === \"disconnected\")\n\t\t\t\treturn Promise.resolve();\n\t\t\tif (current.status === \"connecting\") {\n\t\t\t\tcurrent.abort();\n\t\t\t\treturn Promise.resolve();\n\t\t\t}\n\t\t\tif (current.disconnecting) return current.disconnecting;\n\n\t\t\tconst disconnecting = (async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait adapter.disconnect?.(source, walletId);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!teardown.signal.aborted) {\n\t\t\t\t\t\tsetConnection(walletId, {\n\t\t\t\t\t\t\tstatus: \"connected\",\n\t\t\t\t\t\t\thandle: current.handle,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tstore.rememberWallet(walletId);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tif (teardown.signal.aborted) return;\n\t\t\t\tsetConnection(walletId, undefined);\n\t\t\t\tadapter.onDisconnected?.(walletId);\n\t\t\t})();\n\t\t\tsetConnection(walletId, { ...current, disconnecting });\n\t\t\treturn disconnecting;\n\t\t};\n\n\t\tconst sub = combineLatest([adapter.sources$, connections$])\n\t\t\t.pipe(\n\t\t\t\ttap(([sources]) => abortConnectsOfSourcesThatLeft(sources)),\n\t\t\t\tmap(([sources, connections]) =>\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\tconst connection = connections.get(walletId);\n\t\t\t\t\t\tconst connected =\n\t\t\t\t\t\t\tconnection?.status === \"connected\" ? connection : undefined;\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: connected?.handle,\n\t\t\t\t\t\t\tstatus: connection?.status ?? \"disconnected\",\n\t\t\t\t\t\t\terror:\n\t\t\t\t\t\t\t\tconnection?.status === \"disconnected\"\n\t\t\t\t\t\t\t\t\t? connection.error\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\tisConnected: connected !== undefined,\n\t\t\t\t\t\t\tconnect: (options) => connect(source, walletId, options),\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\tteardown.abort();\n\t\t\tfor (const connection of connections$.value.values())\n\t\t\t\tif (connection.status === \"connecting\") connection.abort();\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n"],"mappings":";;;;;;;AAkBA,MAAM,gBAGL,GACA,MACa;CACb,IAAI,EAAE,WAAW,EAAE,QAAQ,OAAO;CAClC,OAAO,EAAE,OACP,GAAG,MACH,EAAE,OAAO,EAAE,EAAE,EAAE,MACf,EAAE,WAAW,EAAE,EAAE,EAAE,UACnB,EAAE,UAAU,EAAE,EAAE,EAAE,SAClB,EAAE,SAAS,EAAE,EAAE,EAAE,IACnB;AACD;AAmEA,MAAM,QACL,YACA,UACA,WACmB;CACnB,IAAI,CAAC,QAAQ;EACZ,WAAW,WAAW;EACtB,OAAO,WAAW;CACnB;CACA,WAAW;CACX,OAAO,IAAI,SAAe,SAAS,WAAW;EAC7C,MAAM,cAAc;GACnB,IAAI,WAAW,UAAU;GACzB,OAAOA,eAAAA,aAAa,UAAU,SAAS,CAAC;GACxC,WAAW;GACX,IAAI,CAAC,WAAW,YAAY,WAAW,YAAY,GAAG,WAAW,MAAM;EACxE;EACA,OAAO,iBAAiB,SAAS,OAAO,EAAE,MAAM,KAAK,CAAC;EACtD,WAAW,QACT,KAAK,SAAS,MAAM,CAAC,CACrB,cAAc,OAAO,oBAAoB,SAAS,KAAK,CAAC;CAC3D,CAAC;AACF;;;;;;;;AASA,MAAa,0BAKZ,OACA,YAEA,IAAIC,KAA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B,OACC,YAAY,WAAW,iBACpB,WAAW,QACX,KAAA;GACJ,aAAa,cAAc,KAAA;GAC3B,UAAU,YAAY,QAAQ,QAAQ,UAAU,OAAO;GACvD,kBAAkB,WAAW,QAAQ,QAAQ;EAC9C,CAAC;CACF,CAAC,CACF,IAAA,GACAC,KAAAA,qBAAAA,CAAqB,YAAY,CAClC,CAAC,CACA,UAAU,UAAU;CAEtB,aAAa;EACZ,SAAS,MAAM;EACf,KAAK,MAAM,cAAc,aAAa,MAAM,OAAO,GAClD,IAAI,WAAW,WAAW,cAAc,WAAW,MAAM;EAC1D,IAAI,YAAY;CACjB;AACD,CAAC,CAAC,CAAC,MAAA,GAAKC,KAAAA,YAAAA,CAAY;CAAE,UAAU;CAAM,YAAY;AAAE,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as abortedError, o as toConnectError } from "./errors-BBTNA4Pk.mjs";
|
|
2
2
|
import { BehaviorSubject, Observable, combineLatest, distinctUntilChanged, map, shareReplay, tap } from "rxjs";
|
|
3
3
|
//#region src/api/injectedWallets.ts
|
|
4
4
|
/**
|
|
@@ -170,4 +170,4 @@ const createInjectedWallets$ = (store, adapter) => new Observable((subscriber) =
|
|
|
170
170
|
//#endregion
|
|
171
171
|
export { createInjectedWallets$ as t };
|
|
172
172
|
|
|
173
|
-
//# sourceMappingURL=injectedWallets-
|
|
173
|
+
//# sourceMappingURL=injectedWallets-Do5__knh.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectedWallets-DHf2lYVb.mjs","names":[],"sources":["../src/api/injectedWallets.ts"],"sourcesContent":["import {\n\tBehaviorSubject,\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tshareReplay,\n\ttap,\n} from \"rxjs\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport { abortedError, type KheopskitError, toConnectError } from \"./errors\";\nimport type { KheopskitStore } from \"./store\";\nimport type { BaseWallet, ConnectOptions, WalletStatus } 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\" | \"status\" | \"error\" | \"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.status === b[i]?.status &&\n\t\t\tw.error === b[i]?.error &&\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 */\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. The resolved value is retained as the wallet's\n\t * live handle until disconnect.\n\t */\n\tconnect: (source: TSource, walletId: WalletId) => Promise<THandle>;\n\t/** `true` maps the platform's rejection to `USER_REJECTED`; absent means never. */\n\tisUserRejection?: (error: unknown) => boolean;\n\treleaseAbandonedHandle?: (handle: THandle, walletId: WalletId) => void;\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\tstatus: WalletStatus;\n\t\terror: KheopskitError | undefined;\n\t\tisConnected: boolean;\n\t\tconnect: (options?: ConnectOptions) => Promise<void>;\n\t\tdisconnect: () => Promise<void>;\n\t}) => TWallet;\n};\n\ntype Connecting = {\n\tstatus: \"connecting\";\n\tpromise: Promise<void>;\n\tanchored: boolean;\n\twaiting: number;\n\tanswered: boolean;\n\tabort: () => void;\n};\n\ntype Connection<THandle> =\n\t| Connecting\n\t| { status: \"connected\"; handle: THandle; disconnecting?: Promise<void> }\n\t| { status: \"disconnected\"; error: KheopskitError };\n\nconst join = (\n\tconnecting: Connecting,\n\twalletId: WalletId,\n\tsignal: AbortSignal | undefined,\n): Promise<void> => {\n\tif (!signal) {\n\t\tconnecting.anchored = true;\n\t\treturn connecting.promise;\n\t}\n\tconnecting.waiting++;\n\treturn new Promise<void>((resolve, reject) => {\n\t\tconst leave = () => {\n\t\t\tif (connecting.answered) return;\n\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\tconnecting.waiting--;\n\t\t\tif (!connecting.anchored && connecting.waiting === 0) connecting.abort();\n\t\t};\n\t\tsignal.addEventListener(\"abort\", leave, { once: true });\n\t\tconnecting.promise\n\t\t\t.then(resolve, reject)\n\t\t\t.finally(() => signal.removeEventListener(\"abort\", leave));\n\t});\n};\n\n/**\n * The shared engine behind every platform's injected-wallets stream: tracks\n * each wallet's connection (pending attempt or live handle), shares one\n * in-flight connect per wallet, persists connected ids to the store for\n * auto-reconnect, and re-emits the wallet list whenever the registry or\n * connection state 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 connections$ = new BehaviorSubject<\n\t\t\tReadonlyMap<WalletId, Connection<THandle>>\n\t\t>(new Map());\n\t\tconst teardown = new AbortController();\n\t\tlet present = new Set<WalletId>();\n\n\t\tconst abortConnectsOfSourcesThatLeft = (sources: readonly TSource[]) => {\n\t\t\tpresent = new Set(sources.map((source) => adapter.getWalletId(source)));\n\t\t\tfor (const [walletId, connection] of connections$.value)\n\t\t\t\tif (connection.status === \"connecting\" && !present.has(walletId))\n\t\t\t\t\tconnection.abort();\n\t\t};\n\n\t\tconst setConnection = (\n\t\t\twalletId: WalletId,\n\t\t\tconnection: Connection<THandle> | undefined,\n\t\t) => {\n\t\t\tconst next = new Map(connections$.value);\n\t\t\tif (connection) next.set(walletId, connection);\n\t\t\telse next.delete(walletId);\n\t\t\tconnections$.next(next);\n\t\t};\n\n\t\tconst startConnect = (\n\t\t\tsource: TSource,\n\t\t\twalletId: WalletId,\n\t\t\tsignal: AbortSignal | undefined,\n\t\t): Promise<void> => {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst promise = new Promise<void>((resolve, reject) => {\n\t\t\t\tcontroller.signal.addEventListener(\n\t\t\t\t\t\"abort\",\n\t\t\t\t\t() => {\n\t\t\t\t\t\tsetConnection(walletId, undefined);\n\t\t\t\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\t\t\t},\n\t\t\t\t\t{ once: true },\n\t\t\t\t);\n\t\t\t\tnew Promise<THandle>((res) =>\n\t\t\t\t\tres(adapter.connect(source, walletId)),\n\t\t\t\t).then(\n\t\t\t\t\t(handle) => {\n\t\t\t\t\t\tconnecting.answered = true;\n\t\t\t\t\t\tif (controller.signal.aborted) {\n\t\t\t\t\t\t\tadapter.releaseAbandonedHandle?.(handle, walletId);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsetConnection(walletId, { status: \"connected\", handle });\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t\tstore.rememberWallet(walletId);\n\t\t\t\t\t},\n\t\t\t\t\t(error) => {\n\t\t\t\t\t\tconnecting.answered = true;\n\t\t\t\t\t\tif (controller.signal.aborted) return;\n\t\t\t\t\t\tconst connectError = toConnectError(\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\twalletId,\n\t\t\t\t\t\t\tadapter.isUserRejection ?? (() => false),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tsetConnection(walletId, {\n\t\t\t\t\t\t\tstatus: \"disconnected\",\n\t\t\t\t\t\t\terror: connectError,\n\t\t\t\t\t\t});\n\t\t\t\t\t\treject(connectError);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t\tconst connecting: Connecting = {\n\t\t\t\tstatus: \"connecting\",\n\t\t\t\tpromise,\n\t\t\t\tanchored: false,\n\t\t\t\twaiting: 0,\n\t\t\t\tanswered: false,\n\t\t\t\tabort: () => {\n\t\t\t\t\tif (connections$.value.get(walletId) === connecting)\n\t\t\t\t\t\tcontroller.abort();\n\t\t\t\t},\n\t\t\t};\n\t\t\tsetConnection(walletId, connecting);\n\t\t\treturn join(connecting, walletId, signal);\n\t\t};\n\n\t\tconst untilSettled = (\n\t\t\tdisconnecting: Promise<void>,\n\t\t\twalletId: WalletId,\n\t\t\tsignal: AbortSignal | undefined,\n\t\t): Promise<void> =>\n\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\tconst signals = signal ? [teardown.signal, signal] : [teardown.signal];\n\t\t\t\tconst settle = () => {\n\t\t\t\t\tfor (const s of signals) s.removeEventListener(\"abort\", settle);\n\t\t\t\t\tif (signals.some((s) => s.aborted))\n\t\t\t\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\t\t\telse resolve();\n\t\t\t\t};\n\t\t\t\tif (signals.some((s) => s.aborted)) return settle();\n\t\t\t\tfor (const s of signals)\n\t\t\t\t\ts.addEventListener(\"abort\", settle, { once: true });\n\t\t\t\tdisconnecting.then(settle, settle);\n\t\t\t});\n\n\t\tconst connect = (\n\t\t\tsource: TSource,\n\t\t\twalletId: WalletId,\n\t\t\toptions?: ConnectOptions,\n\t\t): Promise<void> => {\n\t\t\tif (teardown.signal.aborted || !present.has(walletId))\n\t\t\t\treturn Promise.reject(abortedError(walletId, \"connect\"));\n\t\t\tconst current = connections$.value.get(walletId);\n\t\t\tif (current?.status === \"connected\") {\n\t\t\t\tif (!current.disconnecting) return Promise.resolve();\n\t\t\t\treturn untilSettled(\n\t\t\t\t\tcurrent.disconnecting,\n\t\t\t\t\twalletId,\n\t\t\t\t\toptions?.signal,\n\t\t\t\t).then(() => connect(source, walletId, options));\n\t\t\t}\n\t\t\tif (options?.signal?.aborted)\n\t\t\t\treturn Promise.reject(abortedError(walletId, \"connect\"));\n\t\t\tif (current?.status === \"connecting\")\n\t\t\t\treturn join(current, walletId, options?.signal);\n\t\t\treturn startConnect(source, walletId, options?.signal);\n\t\t};\n\n\t\tconst disconnect = (source: TSource, walletId: WalletId): Promise<void> => {\n\t\t\tconst current = connections$.value.get(walletId);\n\t\t\tstore.forgetWallet(walletId);\n\t\t\tif (!current || current.status === \"disconnected\")\n\t\t\t\treturn Promise.resolve();\n\t\t\tif (current.status === \"connecting\") {\n\t\t\t\tcurrent.abort();\n\t\t\t\treturn Promise.resolve();\n\t\t\t}\n\t\t\tif (current.disconnecting) return current.disconnecting;\n\n\t\t\tconst disconnecting = (async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait adapter.disconnect?.(source, walletId);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!teardown.signal.aborted) {\n\t\t\t\t\t\tsetConnection(walletId, {\n\t\t\t\t\t\t\tstatus: \"connected\",\n\t\t\t\t\t\t\thandle: current.handle,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tstore.rememberWallet(walletId);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tif (teardown.signal.aborted) return;\n\t\t\t\tsetConnection(walletId, undefined);\n\t\t\t\tadapter.onDisconnected?.(walletId);\n\t\t\t})();\n\t\t\tsetConnection(walletId, { ...current, disconnecting });\n\t\t\treturn disconnecting;\n\t\t};\n\n\t\tconst sub = combineLatest([adapter.sources$, connections$])\n\t\t\t.pipe(\n\t\t\t\ttap(([sources]) => abortConnectsOfSourcesThatLeft(sources)),\n\t\t\t\tmap(([sources, connections]) =>\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\tconst connection = connections.get(walletId);\n\t\t\t\t\t\tconst connected =\n\t\t\t\t\t\t\tconnection?.status === \"connected\" ? connection : undefined;\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: connected?.handle,\n\t\t\t\t\t\t\tstatus: connection?.status ?? \"disconnected\",\n\t\t\t\t\t\t\terror:\n\t\t\t\t\t\t\t\tconnection?.status === \"disconnected\"\n\t\t\t\t\t\t\t\t\t? connection.error\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\tisConnected: connected !== undefined,\n\t\t\t\t\t\t\tconnect: (options) => connect(source, walletId, options),\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\tteardown.abort();\n\t\t\tfor (const connection of connections$.value.values())\n\t\t\t\tif (connection.status === \"connecting\") connection.abort();\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n"],"mappings":";;;;;;;AAkBA,MAAM,gBAGL,GACA,MACa;CACb,IAAI,EAAE,WAAW,EAAE,QAAQ,OAAO;CAClC,OAAO,EAAE,OACP,GAAG,MACH,EAAE,OAAO,EAAE,EAAE,EAAE,MACf,EAAE,WAAW,EAAE,EAAE,EAAE,UACnB,E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B,QAAQ;EAClC,EAAA,CAAG;EACH,cAAc,UAAU;GAAE,GAAG;GAAS;EAAc,CAAC;EACrD,OAAO;CACR;CAEA,MAAM,MAAM,cAAc,CAAC,QAAQ,UAAU,YAAY,CAAC,CAAC,CACzD,KACA,KAAK,CAAC,aAAa,+BAA+B,OAAO,CAAC,GAC1D,KAAK,CAAC,SAAS,iBACd,QAAQ,KAAK,WAAoB;EAChC,MAAM,WAAW,QAAQ,YAAY,MAAM;EAC3C,MAAM,aAAa,YAAY,IAAI,QAAQ;EAC3C,MAAM,YACL,YAAY,WAAW,cAAc,aAAa,KAAA;EACnD,OAAO,QAAQ,YAAY;GAC1B;GACA;GACA,QAAQ,WAAW;GACnB,QAAQ,YAAY,UAAU;GAC9B,OACC,YAAY,WAAW,iBACpB,WAAW,QACX,KAAA;GACJ,aAAa,cAAc,KAAA;GAC3B,UAAU,YAAY,QAAQ,QAAQ,UAAU,OAAO;GACvD,kBAAkB,WAAW,QAAQ,QAAQ;EAC9C,CAAC;CACF,CAAC,CACF,GACA,qBAAqB,YAAY,CAClC,CAAC,CACA,UAAU,UAAU;CAEtB,aAAa;EACZ,SAAS,MAAM;EACf,KAAK,MAAM,cAAc,aAAa,MAAM,OAAO,GAClD,IAAI,WAAW,WAAW,cAAc,WAAW,MAAM;EAC1D,IAAI,YAAY;CACjB;AACD,CAAC,CAAC,CAAC,KAAK,YAAY;CAAE,UAAU;CAAM,YAAY;AAAE,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"injectedWallets-Do5__knh.mjs","names":[],"sources":["../src/api/injectedWallets.ts"],"sourcesContent":["import {\n\tBehaviorSubject,\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tshareReplay,\n\ttap,\n} from \"rxjs\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport { abortedError, type KheopskitError, toConnectError } from \"./errors\";\nimport type { KheopskitStore } from \"./store\";\nimport type { BaseWallet, ConnectOptions, WalletStatus } 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\" | \"status\" | \"error\" | \"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.status === b[i]?.status &&\n\t\t\tw.error === b[i]?.error &&\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 */\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. The resolved value is retained as the wallet's\n\t * live handle until disconnect.\n\t */\n\tconnect: (source: TSource, walletId: WalletId) => Promise<THandle>;\n\t/** `true` maps the platform's rejection to `USER_REJECTED`; absent means never. */\n\tisUserRejection?: (error: unknown) => boolean;\n\treleaseAbandonedHandle?: (handle: THandle, walletId: WalletId) => void;\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\tstatus: WalletStatus;\n\t\terror: KheopskitError | undefined;\n\t\tisConnected: boolean;\n\t\tconnect: (options?: ConnectOptions) => Promise<void>;\n\t\tdisconnect: () => Promise<void>;\n\t}) => TWallet;\n};\n\ntype Connecting = {\n\tstatus: \"connecting\";\n\tpromise: Promise<void>;\n\tanchored: boolean;\n\twaiting: number;\n\tanswered: boolean;\n\tabort: () => void;\n};\n\ntype Connection<THandle> =\n\t| Connecting\n\t| { status: \"connected\"; handle: THandle; disconnecting?: Promise<void> }\n\t| { status: \"disconnected\"; error: KheopskitError };\n\nconst join = (\n\tconnecting: Connecting,\n\twalletId: WalletId,\n\tsignal: AbortSignal | undefined,\n): Promise<void> => {\n\tif (!signal) {\n\t\tconnecting.anchored = true;\n\t\treturn connecting.promise;\n\t}\n\tconnecting.waiting++;\n\treturn new Promise<void>((resolve, reject) => {\n\t\tconst leave = () => {\n\t\t\tif (connecting.answered) return;\n\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\tconnecting.waiting--;\n\t\t\tif (!connecting.anchored && connecting.waiting === 0) connecting.abort();\n\t\t};\n\t\tsignal.addEventListener(\"abort\", leave, { once: true });\n\t\tconnecting.promise\n\t\t\t.then(resolve, reject)\n\t\t\t.finally(() => signal.removeEventListener(\"abort\", leave));\n\t});\n};\n\n/**\n * The shared engine behind every platform's injected-wallets stream: tracks\n * each wallet's connection (pending attempt or live handle), shares one\n * in-flight connect per wallet, persists connected ids to the store for\n * auto-reconnect, and re-emits the wallet list whenever the registry or\n * connection state 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 connections$ = new BehaviorSubject<\n\t\t\tReadonlyMap<WalletId, Connection<THandle>>\n\t\t>(new Map());\n\t\tconst teardown = new AbortController();\n\t\tlet present = new Set<WalletId>();\n\n\t\tconst abortConnectsOfSourcesThatLeft = (sources: readonly TSource[]) => {\n\t\t\tpresent = new Set(sources.map((source) => adapter.getWalletId(source)));\n\t\t\tfor (const [walletId, connection] of connections$.value)\n\t\t\t\tif (connection.status === \"connecting\" && !present.has(walletId))\n\t\t\t\t\tconnection.abort();\n\t\t};\n\n\t\tconst setConnection = (\n\t\t\twalletId: WalletId,\n\t\t\tconnection: Connection<THandle> | undefined,\n\t\t) => {\n\t\t\tconst next = new Map(connections$.value);\n\t\t\tif (connection) next.set(walletId, connection);\n\t\t\telse next.delete(walletId);\n\t\t\tconnections$.next(next);\n\t\t};\n\n\t\tconst startConnect = (\n\t\t\tsource: TSource,\n\t\t\twalletId: WalletId,\n\t\t\tsignal: AbortSignal | undefined,\n\t\t): Promise<void> => {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst promise = new Promise<void>((resolve, reject) => {\n\t\t\t\tcontroller.signal.addEventListener(\n\t\t\t\t\t\"abort\",\n\t\t\t\t\t() => {\n\t\t\t\t\t\tsetConnection(walletId, undefined);\n\t\t\t\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\t\t\t},\n\t\t\t\t\t{ once: true },\n\t\t\t\t);\n\t\t\t\tnew Promise<THandle>((res) =>\n\t\t\t\t\tres(adapter.connect(source, walletId)),\n\t\t\t\t).then(\n\t\t\t\t\t(handle) => {\n\t\t\t\t\t\tconnecting.answered = true;\n\t\t\t\t\t\tif (controller.signal.aborted) {\n\t\t\t\t\t\t\tadapter.releaseAbandonedHandle?.(handle, walletId);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsetConnection(walletId, { status: \"connected\", handle });\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t\tstore.rememberWallet(walletId);\n\t\t\t\t\t},\n\t\t\t\t\t(error) => {\n\t\t\t\t\t\tconnecting.answered = true;\n\t\t\t\t\t\tif (controller.signal.aborted) return;\n\t\t\t\t\t\tconst connectError = toConnectError(\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\twalletId,\n\t\t\t\t\t\t\tadapter.isUserRejection ?? (() => false),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tsetConnection(walletId, {\n\t\t\t\t\t\t\tstatus: \"disconnected\",\n\t\t\t\t\t\t\terror: connectError,\n\t\t\t\t\t\t});\n\t\t\t\t\t\treject(connectError);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t\tconst connecting: Connecting = {\n\t\t\t\tstatus: \"connecting\",\n\t\t\t\tpromise,\n\t\t\t\tanchored: false,\n\t\t\t\twaiting: 0,\n\t\t\t\tanswered: false,\n\t\t\t\tabort: () => {\n\t\t\t\t\tif (connections$.value.get(walletId) === connecting)\n\t\t\t\t\t\tcontroller.abort();\n\t\t\t\t},\n\t\t\t};\n\t\t\tsetConnection(walletId, connecting);\n\t\t\treturn join(connecting, walletId, signal);\n\t\t};\n\n\t\tconst untilSettled = (\n\t\t\tdisconnecting: Promise<void>,\n\t\t\twalletId: WalletId,\n\t\t\tsignal: AbortSignal | undefined,\n\t\t): Promise<void> =>\n\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\tconst signals = signal ? [teardown.signal, signal] : [teardown.signal];\n\t\t\t\tconst settle = () => {\n\t\t\t\t\tfor (const s of signals) s.removeEventListener(\"abort\", settle);\n\t\t\t\t\tif (signals.some((s) => s.aborted))\n\t\t\t\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\t\t\telse resolve();\n\t\t\t\t};\n\t\t\t\tif (signals.some((s) => s.aborted)) return settle();\n\t\t\t\tfor (const s of signals)\n\t\t\t\t\ts.addEventListener(\"abort\", settle, { once: true });\n\t\t\t\tdisconnecting.then(settle, settle);\n\t\t\t});\n\n\t\tconst connect = (\n\t\t\tsource: TSource,\n\t\t\twalletId: WalletId,\n\t\t\toptions?: ConnectOptions,\n\t\t): Promise<void> => {\n\t\t\tif (teardown.signal.aborted || !present.has(walletId))\n\t\t\t\treturn Promise.reject(abortedError(walletId, \"connect\"));\n\t\t\tconst current = connections$.value.get(walletId);\n\t\t\tif (current?.status === \"connected\") {\n\t\t\t\tif (!current.disconnecting) return Promise.resolve();\n\t\t\t\treturn untilSettled(\n\t\t\t\t\tcurrent.disconnecting,\n\t\t\t\t\twalletId,\n\t\t\t\t\toptions?.signal,\n\t\t\t\t).then(() => connect(source, walletId, options));\n\t\t\t}\n\t\t\tif (options?.signal?.aborted)\n\t\t\t\treturn Promise.reject(abortedError(walletId, \"connect\"));\n\t\t\tif (current?.status === \"connecting\")\n\t\t\t\treturn join(current, walletId, options?.signal);\n\t\t\treturn startConnect(source, walletId, options?.signal);\n\t\t};\n\n\t\tconst disconnect = (source: TSource, walletId: WalletId): Promise<void> => {\n\t\t\tconst current = connections$.value.get(walletId);\n\t\t\tstore.forgetWallet(walletId);\n\t\t\tif (!current || current.status === \"disconnected\")\n\t\t\t\treturn Promise.resolve();\n\t\t\tif (current.status === \"connecting\") {\n\t\t\t\tcurrent.abort();\n\t\t\t\treturn Promise.resolve();\n\t\t\t}\n\t\t\tif (current.disconnecting) return current.disconnecting;\n\n\t\t\tconst disconnecting = (async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait adapter.disconnect?.(source, walletId);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!teardown.signal.aborted) {\n\t\t\t\t\t\tsetConnection(walletId, {\n\t\t\t\t\t\t\tstatus: \"connected\",\n\t\t\t\t\t\t\thandle: current.handle,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tstore.rememberWallet(walletId);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tif (teardown.signal.aborted) return;\n\t\t\t\tsetConnection(walletId, undefined);\n\t\t\t\tadapter.onDisconnected?.(walletId);\n\t\t\t})();\n\t\t\tsetConnection(walletId, { ...current, disconnecting });\n\t\t\treturn disconnecting;\n\t\t};\n\n\t\tconst sub = combineLatest([adapter.sources$, connections$])\n\t\t\t.pipe(\n\t\t\t\ttap(([sources]) => abortConnectsOfSourcesThatLeft(sources)),\n\t\t\t\tmap(([sources, connections]) =>\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\tconst connection = connections.get(walletId);\n\t\t\t\t\t\tconst connected =\n\t\t\t\t\t\t\tconnection?.status === \"connected\" ? connection : undefined;\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: connected?.handle,\n\t\t\t\t\t\t\tstatus: connection?.status ?? \"disconnected\",\n\t\t\t\t\t\t\terror:\n\t\t\t\t\t\t\t\tconnection?.status === \"disconnected\"\n\t\t\t\t\t\t\t\t\t? connection.error\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\tisConnected: connected !== undefined,\n\t\t\t\t\t\t\tconnect: (options) => connect(source, walletId, options),\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\tteardown.abort();\n\t\t\tfor (const connection of connections$.value.values())\n\t\t\t\tif (connection.status === \"connecting\") connection.abort();\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n"],"mappings":";;;;;;;AAkBA,MAAM,gBAGL,GACA,MACa;CACb,IAAI,EAAE,WAAW,EAAE,QAAQ,OAAO;CAClC,OAAO,EAAE,OACP,GAAG,MACH,EAAE,OAAO,EAAE,EAAE,EAAE,MACf,EAAE,WAAW,EAAE,EAAE,EAAE,UACnB,EAAE,UAAU,EAAE,EAAE,EAAE,SAClB,E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