@kheopskit/core 1.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATING_TO_V4.md +259 -0
- package/README.md +67 -0
- package/dist/chunk-4RBYRNY3.mjs +164 -0
- package/dist/chunk-4RBYRNY3.mjs.map +1 -0
- package/dist/chunk-BWUUHUDK.mjs +24 -0
- package/dist/chunk-BWUUHUDK.mjs.map +1 -0
- package/dist/chunk-D3EQMFZ2.js +24 -0
- package/dist/chunk-D3EQMFZ2.js.map +1 -0
- package/dist/chunk-FIAL4HTE.js +1 -0
- package/dist/chunk-FIAL4HTE.js.map +1 -0
- package/dist/chunk-KWFQDD7E.mjs +578 -0
- package/dist/chunk-KWFQDD7E.mjs.map +1 -0
- package/dist/chunk-NU46D4MZ.js +578 -0
- package/dist/chunk-NU46D4MZ.js.map +1 -0
- package/dist/chunk-PNPPI5CH.mjs +201 -0
- package/dist/chunk-PNPPI5CH.mjs.map +1 -0
- package/dist/chunk-SIUWQBT4.js +201 -0
- package/dist/chunk-SIUWQBT4.js.map +1 -0
- package/dist/chunk-TMAPQWW2.js +164 -0
- package/dist/chunk-TMAPQWW2.js.map +1 -0
- package/dist/chunk-YFD3IKK5.mjs +1 -0
- package/dist/chunk-YFD3IKK5.mjs.map +1 -0
- package/dist/ethereum.d.mts +60 -0
- package/dist/ethereum.d.ts +60 -0
- package/dist/ethereum.js +332 -0
- package/dist/ethereum.js.map +1 -0
- package/dist/ethereum.mjs +332 -0
- package/dist/ethereum.mjs.map +1 -0
- package/dist/getCachedObservable-C4E8dfMp.d.mts +20 -0
- package/dist/getCachedObservable-C4E8dfMp.d.ts +20 -0
- package/dist/index.d.mts +44 -270
- package/dist/index.d.ts +44 -270
- package/dist/index.js +160 -1394
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +119 -1387
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.mts +86 -0
- package/dist/internal.d.ts +86 -0
- package/dist/internal.js +32 -0
- package/dist/internal.js.map +1 -0
- package/dist/internal.mjs +32 -0
- package/dist/internal.mjs.map +1 -0
- package/dist/polkadot.d.mts +69 -0
- package/dist/polkadot.d.ts +69 -0
- package/dist/polkadot.js +314 -0
- package/dist/polkadot.js.map +1 -0
- package/dist/polkadot.mjs +314 -0
- package/dist/polkadot.mjs.map +1 -0
- package/dist/solana.d.mts +97 -0
- package/dist/solana.d.ts +97 -0
- package/dist/solana.js +466 -0
- package/dist/solana.js.map +1 -0
- package/dist/solana.mjs +466 -0
- package/dist/solana.mjs.map +1 -0
- package/dist/types-BNzRUNw-.d.mts +319 -0
- package/dist/types-BNzRUNw-.d.ts +319 -0
- package/package.json +76 -16
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkD3EQMFZ2js = require('./chunk-D3EQMFZ2.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkSIUWQBT4js = require('./chunk-SIUWQBT4.js');
|
|
8
|
+
|
|
9
|
+
// src/utils/hydrateState.ts
|
|
10
|
+
var lookupWalletIcon = (platform, identifier) => {
|
|
11
|
+
if (platform === "polkadot") {
|
|
12
|
+
return _nullishCoalesce(_optionalChain([_chunkD3EQMFZ2js.POLKADOT_EXTENSIONS, 'access', _ => _[identifier], 'optionalAccess', _2 => _2.icon]), () => ( ""));
|
|
13
|
+
}
|
|
14
|
+
return "";
|
|
15
|
+
};
|
|
16
|
+
var PendingWalletError = class extends Error {
|
|
17
|
+
constructor(walletId) {
|
|
18
|
+
super(
|
|
19
|
+
`Wallet ${walletId} is still loading. Wait for isHydrating to be false before calling connect/disconnect.`
|
|
20
|
+
);
|
|
21
|
+
this.name = "PendingWalletError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var hydrateWallet = (cached) => {
|
|
25
|
+
const { platform, identifier } = _chunkSIUWQBT4js.parseWalletId.call(void 0, cached.id);
|
|
26
|
+
const throwPending = () => {
|
|
27
|
+
throw new PendingWalletError(cached.id);
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
id: cached.id,
|
|
31
|
+
platform: cached.platform,
|
|
32
|
+
type: cached.type,
|
|
33
|
+
name: cached.name,
|
|
34
|
+
icon: lookupWalletIcon(platform, identifier),
|
|
35
|
+
isConnected: cached.isConnected,
|
|
36
|
+
connect: throwPending,
|
|
37
|
+
disconnect: throwPending
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
var hydrateAccount = (cached) => ({
|
|
41
|
+
id: cached.id,
|
|
42
|
+
platform: cached.platform,
|
|
43
|
+
address: cached.address,
|
|
44
|
+
name: cached.name,
|
|
45
|
+
walletId: cached.walletId,
|
|
46
|
+
walletName: cached.walletName,
|
|
47
|
+
// Spread (not direct keys) so the extra platform fields don't trip the
|
|
48
|
+
// excess-property check against BaseWalletAccount; they're read back via the
|
|
49
|
+
// platform-specific account types once narrowed by `platform`.
|
|
50
|
+
...cached.platform === "ethereum" && { chainId: cached.chainId },
|
|
51
|
+
...cached.platform === "polkadot" && {
|
|
52
|
+
type: cached.polkadotAccountType
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
var serializeWallet = (wallet) => ({
|
|
56
|
+
id: wallet.id,
|
|
57
|
+
platform: wallet.platform,
|
|
58
|
+
type: wallet.type,
|
|
59
|
+
name: wallet.name,
|
|
60
|
+
// Note: icon is NOT stored to save cookie space
|
|
61
|
+
isConnected: wallet.isConnected
|
|
62
|
+
});
|
|
63
|
+
var serializeAccount = (account) => ({
|
|
64
|
+
id: account.id,
|
|
65
|
+
platform: account.platform,
|
|
66
|
+
address: account.address,
|
|
67
|
+
name: account.name,
|
|
68
|
+
chainId: account.platform === "ethereum" ? account.chainId : void 0,
|
|
69
|
+
polkadotAccountType: account.platform === "polkadot" ? account.type : void 0,
|
|
70
|
+
walletId: account.walletId,
|
|
71
|
+
walletName: account.walletName
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// src/utils/iconCache.ts
|
|
75
|
+
var ICON_CACHE_KEY = "kheopskit-icons";
|
|
76
|
+
var memoryCache = null;
|
|
77
|
+
var loadCache = () => {
|
|
78
|
+
if (memoryCache !== null) return memoryCache;
|
|
79
|
+
try {
|
|
80
|
+
const stored = _chunkSIUWQBT4js.safeLocalStorage.getItem(ICON_CACHE_KEY);
|
|
81
|
+
memoryCache = stored ? JSON.parse(stored) : {};
|
|
82
|
+
} catch (e) {
|
|
83
|
+
memoryCache = {};
|
|
84
|
+
}
|
|
85
|
+
return memoryCache;
|
|
86
|
+
};
|
|
87
|
+
var saveCache = (cache) => {
|
|
88
|
+
try {
|
|
89
|
+
_chunkSIUWQBT4js.safeLocalStorage.setItem(ICON_CACHE_KEY, JSON.stringify(cache));
|
|
90
|
+
memoryCache = cache;
|
|
91
|
+
} catch (e2) {
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var getCachedIcon = (walletId) => {
|
|
95
|
+
const cache = loadCache();
|
|
96
|
+
return cache[walletId] || void 0;
|
|
97
|
+
};
|
|
98
|
+
var setCachedIcons = (icons) => {
|
|
99
|
+
const cache = loadCache();
|
|
100
|
+
let changed = false;
|
|
101
|
+
for (const [walletId, icon] of Object.entries(icons)) {
|
|
102
|
+
if (icon && cache[walletId] !== icon) {
|
|
103
|
+
cache[walletId] = icon;
|
|
104
|
+
changed = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (changed) {
|
|
108
|
+
saveCache(cache);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// src/utils/sortAccounts.ts
|
|
113
|
+
var PLATFORM_ORDER = {
|
|
114
|
+
polkadot: 0,
|
|
115
|
+
ethereum: 1,
|
|
116
|
+
solana: 2
|
|
117
|
+
};
|
|
118
|
+
var byWalletName = (a1, a2) => {
|
|
119
|
+
if (a1.walletName.toLowerCase() === "talisman") return -1;
|
|
120
|
+
if (a2.walletName.toLowerCase() === "talisman") return 1;
|
|
121
|
+
return a1.walletName.localeCompare(a2.walletName);
|
|
122
|
+
};
|
|
123
|
+
var sortAccounts = (a1, a2) => {
|
|
124
|
+
if (a1.platform !== a2.platform)
|
|
125
|
+
return PLATFORM_ORDER[a1.platform] - PLATFORM_ORDER[a2.platform];
|
|
126
|
+
if (a1.walletName !== a2.walletName) return byWalletName(a1, a2);
|
|
127
|
+
if (a1.platform === "polkadot" && a2.platform === "polkadot")
|
|
128
|
+
return a1.name !== a2.name ? (_nullishCoalesce(a1.name, () => ( ""))).localeCompare(_nullishCoalesce(a2.name, () => ( ""))) : a1.address.localeCompare(a2.address);
|
|
129
|
+
return a1.id.localeCompare(a2.id);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/utils/sortWallets.ts
|
|
133
|
+
var PLATFORM_ORDER2 = {
|
|
134
|
+
polkadot: 0,
|
|
135
|
+
ethereum: 1,
|
|
136
|
+
solana: 2
|
|
137
|
+
};
|
|
138
|
+
var sortWallets = (w1, w2) => {
|
|
139
|
+
if (w1.platform !== w2.platform) {
|
|
140
|
+
return PLATFORM_ORDER2[w1.platform] - PLATFORM_ORDER2[w2.platform];
|
|
141
|
+
}
|
|
142
|
+
if (w1.name.toLowerCase() === "talisman") return -1;
|
|
143
|
+
if (w2.name.toLowerCase() === "talisman") return 1;
|
|
144
|
+
return w1.name.localeCompare(w2.name);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// src/api/platform.ts
|
|
148
|
+
var acceptsCachedAccount = (cached, platforms) => {
|
|
149
|
+
const plugin = platforms.find((p) => p.platform === cached.platform);
|
|
150
|
+
return _nullishCoalesce(_optionalChain([plugin, 'optionalAccess', _3 => _3.acceptsCachedAccount, 'optionalCall', _4 => _4(cached)]), () => ( true));
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
exports.hydrateWallet = hydrateWallet; exports.hydrateAccount = hydrateAccount; exports.serializeWallet = serializeWallet; exports.serializeAccount = serializeAccount; exports.getCachedIcon = getCachedIcon; exports.setCachedIcons = setCachedIcons; exports.sortAccounts = sortAccounts; exports.sortWallets = sortWallets; exports.acceptsCachedAccount = acceptsCachedAccount;
|
|
164
|
+
//# sourceMappingURL=chunk-TMAPQWW2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kheopskit/kheopskit/packages/core/dist/chunk-TMAPQWW2.js","../src/utils/hydrateState.ts","../src/utils/iconCache.ts","../src/utils/sortAccounts.ts","../src/utils/sortWallets.ts","../src/api/platform.ts"],"names":["PLATFORM_ORDER"],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACA;ACYA,IAAM,iBAAA,EAAmB,CAAC,QAAA,EAAkB,UAAA,EAAA,GAA+B;AAE1E,EAAA,GAAA,CAAI,SAAA,IAAa,UAAA,EAAY;AAC5B,IAAA,wCAAO,oCAAA,mBAAoB,UAAU,CAAA,6BAAG,MAAA,UAAQ,IAAA;AAAA,EACjD;AAEA,EAAA,OAAO,EAAA;AACR,CAAA;AAKA,IAAM,mBAAA,EAAN,MAAA,QAAiC,MAAM;AAAA,EACtC,WAAA,CAAY,QAAA,EAAkB;AAC7B,IAAA,KAAA;AAAA,MAC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AA,EAAgB,EAAA,EAAA,GAAmB;AAE9D,EAAA,GAAA,CAAI,EAAA,CAAG,SAAA,IAAa,EAAA,CAAG,QAAA,EAAU;AAChC,IAAA,OAAOA,eAAAA,CAAe,EAAA,CAAG,QAAQ,EAAA,EAAIA,eAAAA,CAAe,EAAA,CAAG,QAAQ,CAAA;AAAA,EAChE;AAGA,EAAA,GAAA,CAAI,EAAA,CAAG,IAAA,CAAK,WAAA,CAAY,EAAA,IAAM,UAAA,EAAY,OAAO,CAAA,CAAA;AACjD,EAAA,GAAA,CAAI,EAAA,CAAG,IAAA,CAAK,WAAA,CAAY,EAAA,IAAM,UAAA,EAAY,OAAO,CAAA;AAEjD,EAAA,OAAO,EAAA,CAAG,IAAA,CAAK,aAAA,CAAc,EAAA,CAAG,IAAI,CAAA;AACrC,CAAA;AJ8HA;AACA;AK1IO,IAAM,qBAAA,EAAuB,CACnC,MAAA,EACA,SAAA,EAAA,GACa;AACb,EAAA,MAAM,OAAA,EAAS,SAAA,CAAU,IAAA,CAAK,CAAC,CAAA,EAAA,GAAM,CAAA,CAAE,SAAA,IAAa,MAAA,CAAO,QAAQ,CAAA;AACnE,EAAA,wCAAO,MAAA,6BAAQ,oBAAA,0BAAA,CAAuB,MAAM,GAAA,UAAK,MAAA;AAClD,CAAA;ALyIA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,oXAAC","file":"/home/runner/work/kheopskit/kheopskit/packages/core/dist/chunk-TMAPQWW2.js","sourcesContent":[null,"import type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tCachedAccount,\n\tCachedWallet,\n\tPolkadotAccountType,\n} from \"../api/types\";\nimport { POLKADOT_EXTENSIONS } from \"./polkadotExtensions\";\nimport type { WalletAccountId } from \"./WalletAccountId\";\nimport { parseWalletId, type WalletId } from \"./WalletId\";\n\n/**\n * Looks up the icon for a wallet from known Polkadot extensions only.\n * Ethereum icons will be populated from the localStorage icon cache via the merge function.\n *\n * Note: We DON'T use localStorage icon cache here because hydrateWallet is called\n * during SSR (server) and client hydration. localStorage isn't available on server,\n * so using it would cause a hydration mismatch. Icons for Ethereum wallets will be\n * populated when the hydration buffer merges cached wallets with live wallets.\n */\nconst lookupWalletIcon = (platform: string, identifier: string): string => {\n\t// Only Polkadot extensions have hardcoded icons that are safe for SSR\n\tif (platform === \"polkadot\") {\n\t\treturn POLKADOT_EXTENSIONS[identifier]?.icon ?? \"\";\n\t}\n\t// Ethereum icons come from localStorage or live wallets - not here\n\treturn \"\";\n};\n\n/**\n * Error thrown when trying to use a placeholder wallet that hasn't fully loaded yet.\n */\nclass PendingWalletError extends Error {\n\tconstructor(walletId: string) {\n\t\tsuper(\n\t\t\t`Wallet ${walletId} is still loading. Wait for isHydrating to be false before calling connect/disconnect.`,\n\t\t);\n\t\tthis.name = \"PendingWalletError\";\n\t}\n}\n\n/**\n * Converts a CachedWallet to a placeholder wallet for SSR hydration display.\n *\n * The placeholder carries only the SDK-free {@link BaseWallet} fields; the real\n * wallet (with its injected provider/extension/standard-wallet handle) replaces\n * it once it loads. connect/disconnect throw until then.\n */\nexport const hydrateWallet = (cached: CachedWallet): BaseWallet => {\n\tconst { platform, identifier } = parseWalletId(cached.id);\n\n\tconst throwPending = () => {\n\t\tthrow new PendingWalletError(cached.id);\n\t};\n\n\treturn {\n\t\tid: cached.id,\n\t\tplatform: cached.platform,\n\t\ttype: cached.type,\n\t\tname: cached.name,\n\t\ticon: lookupWalletIcon(platform, identifier),\n\t\tisConnected: cached.isConnected,\n\t\tconnect: throwPending,\n\t\tdisconnect: throwPending,\n\t};\n};\n\n/**\n * Converts a CachedAccount to a placeholder account for SSR hydration display.\n *\n * The placeholder carries the SDK-free {@link BaseWalletAccount} fields plus the\n * plain, serializable platform data that lives in the cache — Ethereum `chainId`\n * and the Polkadot key `type`. Those render immediately on reload (no blank →\n * value flicker) and match what the live account will report. Only the SDK\n * handles (`client`/`signer`/`polkadotSigner`) are absent until the real account\n * replaces this placeholder; signing stays gated on `isHydrating` until then.\n */\nexport const hydrateAccount = (cached: CachedAccount): BaseWalletAccount => ({\n\tid: cached.id as WalletAccountId,\n\tplatform: cached.platform,\n\taddress: cached.address,\n\tname: cached.name,\n\twalletId: cached.walletId,\n\twalletName: cached.walletName,\n\t// Spread (not direct keys) so the extra platform fields don't trip the\n\t// excess-property check against BaseWalletAccount; they're read back via the\n\t// platform-specific account types once narrowed by `platform`.\n\t...(cached.platform === \"ethereum\" && { chainId: cached.chainId }),\n\t...(cached.platform === \"polkadot\" && {\n\t\ttype: cached.polkadotAccountType,\n\t}),\n});\n\n/**\n * Converts a wallet to a CachedWallet for storage.\n * Only extracts the serializable properties needed for hydration.\n */\nexport const serializeWallet = (wallet: BaseWallet): CachedWallet => ({\n\tid: wallet.id,\n\tplatform: wallet.platform,\n\ttype: wallet.type,\n\tname: wallet.name,\n\t// Note: icon is NOT stored to save cookie space\n\tisConnected: wallet.isConnected,\n});\n\n/**\n * Converts an account to a CachedAccount for storage.\n * Only extracts the serializable properties needed for hydration. Platform-only\n * fields (Ethereum chainId, Polkadot key type) are read defensively so this\n * stays SDK-free.\n */\nexport const serializeAccount = (\n\taccount: BaseWalletAccount,\n): CachedAccount => ({\n\tid: account.id,\n\tplatform: account.platform,\n\taddress: account.address,\n\tname: account.name,\n\tchainId:\n\t\taccount.platform === \"ethereum\"\n\t\t\t? (account as { chainId?: number }).chainId\n\t\t\t: undefined,\n\tpolkadotAccountType:\n\t\taccount.platform === \"polkadot\"\n\t\t\t? (account as { type?: PolkadotAccountType }).type\n\t\t\t: undefined,\n\twalletId: account.walletId as WalletId,\n\twalletName: account.walletName,\n});\n","import { safeLocalStorage } from \"./storage\";\n\n/**\n * Storage key for the icon cache in localStorage.\n */\nconst ICON_CACHE_KEY = \"kheopskit-icons\";\n\n/**\n * Icon cache type: a map of wallet ID to icon data URI or URL.\n */\ntype IconCache = Record<string, string>;\n\n/**\n * In-memory cache to avoid repeated localStorage reads.\n */\nlet memoryCache: IconCache | null = null;\n\n/**\n * Loads the icon cache from localStorage.\n */\nconst loadCache = (): IconCache => {\n\tif (memoryCache !== null) return memoryCache;\n\n\ttry {\n\t\tconst stored = safeLocalStorage.getItem(ICON_CACHE_KEY);\n\t\tmemoryCache = stored ? (JSON.parse(stored) as IconCache) : {};\n\t} catch {\n\t\tmemoryCache = {};\n\t}\n\treturn memoryCache;\n};\n\n/**\n * Saves the icon cache to localStorage.\n */\nconst saveCache = (cache: IconCache): void => {\n\ttry {\n\t\tsafeLocalStorage.setItem(ICON_CACHE_KEY, JSON.stringify(cache));\n\t\tmemoryCache = cache;\n\t} catch {\n\t\t// localStorage may be full or unavailable\n\t}\n};\n\n/**\n * Gets a cached icon for a wallet.\n * @param walletId - The wallet ID (e.g., \"ethereum:io.talisman\")\n * @returns The cached icon data URI, or undefined if not cached\n */\nexport const getCachedIcon = (walletId: string): string | undefined => {\n\tconst cache = loadCache();\n\treturn cache[walletId] || undefined;\n};\n\n/**\n * Sets multiple cached icons at once.\n * More efficient than calling setCachedIcon multiple times.\n * @param icons - Map of wallet ID to icon\n */\nexport const setCachedIcons = (icons: Record<string, string>): void => {\n\tconst cache = loadCache();\n\tlet changed = false;\n\n\tfor (const [walletId, icon] of Object.entries(icons)) {\n\t\tif (icon && cache[walletId] !== icon) {\n\t\t\tcache[walletId] = icon;\n\t\t\tchanged = true;\n\t\t}\n\t}\n\n\tif (changed) {\n\t\tsaveCache(cache);\n\t}\n};\n","import type { BaseWalletAccount, WalletPlatform } from \"../api/types\";\n\nconst PLATFORM_ORDER: Record<WalletPlatform, number> = {\n\tpolkadot: 0,\n\tethereum: 1,\n\tsolana: 2,\n};\n\n// Group accounts by wallet, surfacing Talisman first (case-insensitive).\nconst byWalletName = (a1: BaseWalletAccount, a2: BaseWalletAccount) => {\n\tif (a1.walletName.toLowerCase() === \"talisman\") return -1;\n\tif (a2.walletName.toLowerCase() === \"talisman\") return 1;\n\treturn a1.walletName.localeCompare(a2.walletName);\n};\n\nexport const sortAccounts = (a1: BaseWalletAccount, a2: BaseWalletAccount) => {\n\t// Sort by platform first: polkadot, then ethereum, then solana\n\tif (a1.platform !== a2.platform)\n\t\treturn PLATFORM_ORDER[a1.platform] - PLATFORM_ORDER[a2.platform];\n\n\t// Then group by wallet name\n\tif (a1.walletName !== a2.walletName) return byWalletName(a1, a2);\n\n\t// Polkadot accounts expose a friendly name; fall back to address\n\tif (a1.platform === \"polkadot\" && a2.platform === \"polkadot\")\n\t\treturn a1.name !== a2.name\n\t\t\t? (a1.name ?? \"\").localeCompare(a2.name ?? \"\")\n\t\t\t: a1.address.localeCompare(a2.address);\n\n\t// Ethereum and Solana accounts disambiguate by id\n\treturn a1.id.localeCompare(a2.id);\n};\n","import type { BaseWallet, WalletPlatform } from \"../api/types\";\n\nconst PLATFORM_ORDER: Record<WalletPlatform, number> = {\n\tpolkadot: 0,\n\tethereum: 1,\n\tsolana: 2,\n};\n\nexport const sortWallets = (w1: BaseWallet, w2: BaseWallet) => {\n\t// Sort by platform first: polkadot, then ethereum, then solana\n\tif (w1.platform !== w2.platform) {\n\t\treturn PLATFORM_ORDER[w1.platform] - PLATFORM_ORDER[w2.platform];\n\t}\n\n\t// Sort by name, but Talisman first\n\tif (w1.name.toLowerCase() === \"talisman\") return -1;\n\tif (w2.name.toLowerCase() === \"talisman\") return 1;\n\n\treturn w1.name.localeCompare(w2.name);\n};\n","import type { CachedAccount, KheopskitPlatform } from \"./types\";\n\n/**\n * Whether a cached account should survive SSR hydration, per its platform\n * plugin's `acceptsCachedAccount` hook. Plugins without the hook (and platforms\n * with no enabled plugin) accept all — matching the pre-plugin behavior where\n * only Polkadot accounts were filtered (by key type).\n */\nexport const acceptsCachedAccount = (\n\tcached: CachedAccount,\n\tplatforms: readonly KheopskitPlatform[],\n): boolean => {\n\tconst plugin = platforms.find((p) => p.platform === cached.platform);\n\treturn plugin?.acceptsCachedAccount?.(cached) ?? true;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-YFD3IKK5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { W as WalletAccountId, a as WalletId, E as EthereumAppKitWallet, K as KheopskitPlatform } from './types-BNzRUNw-.mjs';
|
|
2
|
+
import { WalletClient, CustomTransport, Account, EIP1193Provider } from 'viem';
|
|
3
|
+
import 'rxjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns true if `address` is a valid Ethereum address.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors viem's `isAddress` (strict): the shape must be `0x` + 40 hex, and a
|
|
9
|
+
* mixed-case address must pass the EIP-55 checksum. All-lowercase addresses are
|
|
10
|
+
* accepted as non-checksummed.
|
|
11
|
+
*/
|
|
12
|
+
declare const isEthereumAddress: (address: string) => boolean;
|
|
13
|
+
|
|
14
|
+
type EthereumInjectedWallet = {
|
|
15
|
+
platform: "ethereum";
|
|
16
|
+
type: "injected";
|
|
17
|
+
id: WalletId;
|
|
18
|
+
/**
|
|
19
|
+
* Stable identifier of the underlying wallet source. For Ethereum this is the
|
|
20
|
+
* EIP-6963 `rdns`. Named consistently across platforms (Solana: Wallet
|
|
21
|
+
* Standard name; Polkadot: extension identifier).
|
|
22
|
+
*/
|
|
23
|
+
sourceId: string;
|
|
24
|
+
provider: EIP1193Provider;
|
|
25
|
+
name: string;
|
|
26
|
+
icon: string;
|
|
27
|
+
isConnected: boolean;
|
|
28
|
+
connect: () => Promise<void>;
|
|
29
|
+
disconnect: () => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
type EthereumWallet = EthereumInjectedWallet | EthereumAppKitWallet;
|
|
32
|
+
type EthereumAccount = {
|
|
33
|
+
id: WalletAccountId;
|
|
34
|
+
platform: "ethereum";
|
|
35
|
+
/**
|
|
36
|
+
* Signing surface for this account: a viem {@link WalletClient} bound to the
|
|
37
|
+
* wallet's provider (sign/send via viem actions). Per-platform signing
|
|
38
|
+
* surfaces differ — Solana exposes `signer`/`getSigner(chain)`, Polkadot
|
|
39
|
+
* exposes `polkadotSigner`. Absent while `state.isHydrating` is `true`.
|
|
40
|
+
*/
|
|
41
|
+
client: WalletClient<CustomTransport, undefined, Account, undefined>;
|
|
42
|
+
address: `0x${string}`;
|
|
43
|
+
/** Current chain ID the wallet is connected to. `undefined` while loading or after provider disconnect. */
|
|
44
|
+
chainId: number | undefined;
|
|
45
|
+
walletName: string;
|
|
46
|
+
walletId: WalletId;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Ethereum platform plugin. Pass to `getKheopskit$({ platforms: [ethereum()] })`.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { ethereum } from "@kheopskit/core/ethereum";
|
|
55
|
+
* ethereum();
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare const ethereum: () => KheopskitPlatform<"ethereum", EthereumWallet, EthereumAccount>;
|
|
59
|
+
|
|
60
|
+
export { type EthereumAccount, EthereumAppKitWallet, type EthereumInjectedWallet, type EthereumWallet, ethereum, isEthereumAddress };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { W as WalletAccountId, a as WalletId, E as EthereumAppKitWallet, K as KheopskitPlatform } from './types-BNzRUNw-.js';
|
|
2
|
+
import { WalletClient, CustomTransport, Account, EIP1193Provider } from 'viem';
|
|
3
|
+
import 'rxjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns true if `address` is a valid Ethereum address.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors viem's `isAddress` (strict): the shape must be `0x` + 40 hex, and a
|
|
9
|
+
* mixed-case address must pass the EIP-55 checksum. All-lowercase addresses are
|
|
10
|
+
* accepted as non-checksummed.
|
|
11
|
+
*/
|
|
12
|
+
declare const isEthereumAddress: (address: string) => boolean;
|
|
13
|
+
|
|
14
|
+
type EthereumInjectedWallet = {
|
|
15
|
+
platform: "ethereum";
|
|
16
|
+
type: "injected";
|
|
17
|
+
id: WalletId;
|
|
18
|
+
/**
|
|
19
|
+
* Stable identifier of the underlying wallet source. For Ethereum this is the
|
|
20
|
+
* EIP-6963 `rdns`. Named consistently across platforms (Solana: Wallet
|
|
21
|
+
* Standard name; Polkadot: extension identifier).
|
|
22
|
+
*/
|
|
23
|
+
sourceId: string;
|
|
24
|
+
provider: EIP1193Provider;
|
|
25
|
+
name: string;
|
|
26
|
+
icon: string;
|
|
27
|
+
isConnected: boolean;
|
|
28
|
+
connect: () => Promise<void>;
|
|
29
|
+
disconnect: () => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
type EthereumWallet = EthereumInjectedWallet | EthereumAppKitWallet;
|
|
32
|
+
type EthereumAccount = {
|
|
33
|
+
id: WalletAccountId;
|
|
34
|
+
platform: "ethereum";
|
|
35
|
+
/**
|
|
36
|
+
* Signing surface for this account: a viem {@link WalletClient} bound to the
|
|
37
|
+
* wallet's provider (sign/send via viem actions). Per-platform signing
|
|
38
|
+
* surfaces differ — Solana exposes `signer`/`getSigner(chain)`, Polkadot
|
|
39
|
+
* exposes `polkadotSigner`. Absent while `state.isHydrating` is `true`.
|
|
40
|
+
*/
|
|
41
|
+
client: WalletClient<CustomTransport, undefined, Account, undefined>;
|
|
42
|
+
address: `0x${string}`;
|
|
43
|
+
/** Current chain ID the wallet is connected to. `undefined` while loading or after provider disconnect. */
|
|
44
|
+
chainId: number | undefined;
|
|
45
|
+
walletName: string;
|
|
46
|
+
walletId: WalletId;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Ethereum platform plugin. Pass to `getKheopskit$({ platforms: [ethereum()] })`.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { ethereum } from "@kheopskit/core/ethereum";
|
|
55
|
+
* ethereum();
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare const ethereum: () => KheopskitPlatform<"ethereum", EthereumWallet, EthereumAccount>;
|
|
59
|
+
|
|
60
|
+
export { type EthereumAccount, EthereumAppKitWallet, type EthereumInjectedWallet, type EthereumWallet, ethereum, isEthereumAddress };
|
package/dist/ethereum.js
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('./chunk-FIAL4HTE.js');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkNU46D4MZjs = require('./chunk-NU46D4MZ.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkSIUWQBT4js = require('./chunk-SIUWQBT4.js');
|
|
14
|
+
|
|
15
|
+
// src/api/ethereum/accounts.ts
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
var _rxjs = require('rxjs');
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var _viem = require('viem');
|
|
31
|
+
var normalizeEvmChainId = (value) => {
|
|
32
|
+
let raw = value;
|
|
33
|
+
if (typeof raw === "string" && raw.startsWith("eip155:")) {
|
|
34
|
+
raw = raw.slice("eip155:".length);
|
|
35
|
+
}
|
|
36
|
+
if (typeof raw === "bigint") {
|
|
37
|
+
return raw >= 0n ? Number(raw) : void 0;
|
|
38
|
+
}
|
|
39
|
+
if (typeof raw === "number") {
|
|
40
|
+
return Number.isInteger(raw) && raw >= 0 ? raw : void 0;
|
|
41
|
+
}
|
|
42
|
+
if (typeof raw === "string") {
|
|
43
|
+
const normalized = raw.trim().toLowerCase();
|
|
44
|
+
if (!normalized) return void 0;
|
|
45
|
+
const parsed = normalized.startsWith("0x") ? Number.parseInt(normalized, 16) : Number.parseInt(normalized, 10);
|
|
46
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
47
|
+
}
|
|
48
|
+
return void 0;
|
|
49
|
+
};
|
|
50
|
+
var toCaipNetworkId = (value) => {
|
|
51
|
+
const chainId = normalizeEvmChainId(value);
|
|
52
|
+
return chainId === void 0 ? void 0 : `eip155:${chainId}`;
|
|
53
|
+
};
|
|
54
|
+
var getInjectedWalletAccounts$ = (wallet) => {
|
|
55
|
+
if (!wallet.isConnected) return _rxjs.of.call(void 0, []);
|
|
56
|
+
return _chunkSIUWQBT4js.getCachedObservable$.call(void 0,
|
|
57
|
+
`accounts:${wallet.id}`,
|
|
58
|
+
() => new (0, _rxjs.Observable)((subscriber) => {
|
|
59
|
+
const addresses$ = new (0, _rxjs.ReplaySubject)(1);
|
|
60
|
+
const chainId$ = new (0, _rxjs.ReplaySubject)(1);
|
|
61
|
+
const getAccount = (address, chainId) => {
|
|
62
|
+
const client = _viem.createWalletClient.call(void 0, {
|
|
63
|
+
account: address,
|
|
64
|
+
transport: _viem.custom.call(void 0, wallet.provider)
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
id: _chunkNU46D4MZjs.getWalletAccountId.call(void 0, wallet.id, address),
|
|
68
|
+
platform: "ethereum",
|
|
69
|
+
client,
|
|
70
|
+
address: _viem.getAddress.call(void 0, address),
|
|
71
|
+
chainId,
|
|
72
|
+
walletName: wallet.name,
|
|
73
|
+
walletId: wallet.id
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
const handleAccountsChanged = (addrs) => {
|
|
77
|
+
addresses$.next(addrs);
|
|
78
|
+
};
|
|
79
|
+
const handleChainChanged = (chainIdHex) => {
|
|
80
|
+
chainId$.next(normalizeEvmChainId(chainIdHex));
|
|
81
|
+
};
|
|
82
|
+
const handleDisconnect = () => {
|
|
83
|
+
chainId$.next(void 0);
|
|
84
|
+
};
|
|
85
|
+
wallet.provider.on("accountsChanged", handleAccountsChanged);
|
|
86
|
+
wallet.provider.on("chainChanged", handleChainChanged);
|
|
87
|
+
wallet.provider.on("disconnect", handleDisconnect);
|
|
88
|
+
wallet.provider.request({ method: "eth_accounts" }).then((addrs) => addresses$.next(addrs)).catch((err) => {
|
|
89
|
+
console.error("Failed to get accounts", err);
|
|
90
|
+
addresses$.next([]);
|
|
91
|
+
});
|
|
92
|
+
wallet.provider.request({ method: "eth_chainId" }).then(handleChainChanged).catch(() => chainId$.next(void 0));
|
|
93
|
+
const sub = _rxjs.combineLatest.call(void 0, [addresses$, chainId$]).pipe(
|
|
94
|
+
_rxjs.map.call(void 0,
|
|
95
|
+
([addresses, chainId]) => addresses.map((addr) => getAccount(addr, chainId))
|
|
96
|
+
)
|
|
97
|
+
).subscribe(subscriber);
|
|
98
|
+
return () => {
|
|
99
|
+
wallet.provider.removeListener(
|
|
100
|
+
"accountsChanged",
|
|
101
|
+
handleAccountsChanged
|
|
102
|
+
);
|
|
103
|
+
wallet.provider.removeListener("chainChanged", handleChainChanged);
|
|
104
|
+
wallet.provider.removeListener("disconnect", handleDisconnect);
|
|
105
|
+
sub.unsubscribe();
|
|
106
|
+
};
|
|
107
|
+
}).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }))
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
var wrapWalletConnectProvider = (provider, sessionTopic, caipNetworkId) => {
|
|
111
|
+
return new Proxy(provider, {
|
|
112
|
+
get(target, prop, receiver) {
|
|
113
|
+
if (prop !== "request") return Reflect.get(target, prop, receiver);
|
|
114
|
+
return (args) => {
|
|
115
|
+
if (args && typeof args === "object" && args.method) {
|
|
116
|
+
if (!args.topic) args.topic = sessionTopic;
|
|
117
|
+
if (!args.chainId) args.chainId = caipNetworkId;
|
|
118
|
+
}
|
|
119
|
+
return target.request(args);
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
var sameAddresses = (a, b) => a.length === b.length && a.every((addr, i) => addr === b[i]);
|
|
125
|
+
var getAppKitAccounts$ = (wallet) => {
|
|
126
|
+
const provider = wallet.appKit.getProvider("eip155");
|
|
127
|
+
if (!wallet.isConnected || !_optionalChain([wallet, 'access', _ => _.appKit, 'optionalAccess', _2 => _2.getAccount, 'call', _3 => _3("eip155"), 'optionalAccess', _4 => _4.allAccounts, 'access', _5 => _5.length]) || !_optionalChain([provider, 'optionalAccess', _6 => _6.session]))
|
|
128
|
+
return _rxjs.of.call(void 0, []);
|
|
129
|
+
return _chunkSIUWQBT4js.getCachedObservable$.call(void 0,
|
|
130
|
+
`accounts:${wallet.id}:`,
|
|
131
|
+
() => new (0, _rxjs.Observable)((subscriber) => {
|
|
132
|
+
const caipNetworkId$ = new (0, _rxjs.ReplaySubject)(1);
|
|
133
|
+
const addresses$ = new (0, _rxjs.ReplaySubject)(1);
|
|
134
|
+
const readAddresses = () => _nullishCoalesce(_optionalChain([wallet, 'access', _7 => _7.appKit, 'access', _8 => _8.getAccount, 'call', _9 => _9("eip155"), 'optionalAccess', _10 => _10.allAccounts, 'access', _11 => _11.map, 'call', _12 => _12((acc) => acc.address)]), () => ( []));
|
|
135
|
+
const handleChainChanged = (chainId) => {
|
|
136
|
+
const caipNetworkId = toCaipNetworkId(chainId);
|
|
137
|
+
if (caipNetworkId) {
|
|
138
|
+
caipNetworkId$.next(caipNetworkId);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const handleAccountsChanged = () => addresses$.next(readAddresses());
|
|
142
|
+
provider.on("chainChanged", handleChainChanged);
|
|
143
|
+
provider.on("accountsChanged", handleAccountsChanged);
|
|
144
|
+
provider.on("session_update", handleAccountsChanged);
|
|
145
|
+
provider.request({ method: "eth_chainId" }).then(handleChainChanged);
|
|
146
|
+
addresses$.next(readAddresses());
|
|
147
|
+
const sub = _rxjs.combineLatest.call(void 0, [
|
|
148
|
+
caipNetworkId$.pipe(_rxjs.distinctUntilChanged.call(void 0, )),
|
|
149
|
+
addresses$.pipe(_rxjs.distinctUntilChanged.call(void 0, sameAddresses))
|
|
150
|
+
]).pipe(
|
|
151
|
+
_rxjs.map.call(void 0, ([caipNetworkId, addresses]) => {
|
|
152
|
+
const chainId = normalizeEvmChainId(caipNetworkId);
|
|
153
|
+
const transport = _viem.custom.call(void 0,
|
|
154
|
+
wrapWalletConnectProvider(
|
|
155
|
+
provider,
|
|
156
|
+
// biome-ignore lint/style/noNonNullAssertion: legacy
|
|
157
|
+
provider.session.topic,
|
|
158
|
+
caipNetworkId
|
|
159
|
+
)
|
|
160
|
+
);
|
|
161
|
+
return addresses.map((addr) => {
|
|
162
|
+
const client = _viem.createWalletClient.call(void 0, {
|
|
163
|
+
account: addr,
|
|
164
|
+
transport
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
id: _chunkNU46D4MZjs.getWalletAccountId.call(void 0, wallet.id, addr),
|
|
168
|
+
platform: "ethereum",
|
|
169
|
+
walletName: wallet.name,
|
|
170
|
+
walletId: wallet.id,
|
|
171
|
+
address: addr,
|
|
172
|
+
client,
|
|
173
|
+
chainId
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
})
|
|
177
|
+
).subscribe(subscriber);
|
|
178
|
+
return () => {
|
|
179
|
+
provider.off("chainChanged", handleChainChanged);
|
|
180
|
+
provider.off("accountsChanged", handleAccountsChanged);
|
|
181
|
+
provider.off("session_update", handleAccountsChanged);
|
|
182
|
+
sub.unsubscribe();
|
|
183
|
+
};
|
|
184
|
+
}).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }))
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
var getEthereumAccounts$ = (ethereumWallets) => new (0, _rxjs.Observable)((subscriber) => {
|
|
188
|
+
const sub = ethereumWallets.pipe(
|
|
189
|
+
_rxjs.map.call(void 0, (wallets) => wallets.filter((w) => w.isConnected)),
|
|
190
|
+
_rxjs.switchMap.call(void 0, (wallets) => {
|
|
191
|
+
return wallets.length ? _rxjs.combineLatest.call(void 0, [
|
|
192
|
+
...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$),
|
|
193
|
+
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$)
|
|
194
|
+
// todo appkit
|
|
195
|
+
]) : _rxjs.of.call(void 0, []);
|
|
196
|
+
}),
|
|
197
|
+
_rxjs.map.call(void 0, (accounts) => accounts.flat()),
|
|
198
|
+
_rxjs.distinctUntilChanged.call(void 0, isSameAccountsList)
|
|
199
|
+
).subscribe(subscriber);
|
|
200
|
+
return () => {
|
|
201
|
+
sub.unsubscribe();
|
|
202
|
+
};
|
|
203
|
+
}).pipe(
|
|
204
|
+
// logObservable("ethereumAccounts$", true),
|
|
205
|
+
_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 })
|
|
206
|
+
);
|
|
207
|
+
var isSameAccountsList = (a, b) => {
|
|
208
|
+
if (a.length !== b.length) return false;
|
|
209
|
+
return a.every(
|
|
210
|
+
(account, i) => account.id === _optionalChain([b, 'access', _13 => _13[i], 'optionalAccess', _14 => _14.id]) && account.chainId === _optionalChain([b, 'access', _15 => _15[i], 'optionalAccess', _16 => _16.chainId])
|
|
211
|
+
);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/api/ethereum/wallets.ts
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
var _mipd = require('mipd');
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
var providersDetails$ = new (0, _rxjs.Observable)(
|
|
227
|
+
(subscriber) => {
|
|
228
|
+
if (typeof window === "undefined") {
|
|
229
|
+
subscriber.next([]);
|
|
230
|
+
return () => {
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
const mipdStore = _mipd.createStore.call(void 0, );
|
|
234
|
+
const unsubscribe = mipdStore.subscribe((providerDetails2) => {
|
|
235
|
+
subscriber.next(providerDetails2);
|
|
236
|
+
});
|
|
237
|
+
const providerDetails = mipdStore.getProviders();
|
|
238
|
+
subscriber.next(providerDetails);
|
|
239
|
+
return () => {
|
|
240
|
+
unsubscribe();
|
|
241
|
+
mipdStore.destroy();
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }));
|
|
245
|
+
var createEthereumInjectedWallets$ = (store2) => new (0, _rxjs.Observable)((subscriber) => {
|
|
246
|
+
const enabledWalletIds$ = new (0, _rxjs.BehaviorSubject)(/* @__PURE__ */ new Set());
|
|
247
|
+
const connectWallet = async (walletId, provider) => {
|
|
248
|
+
if (enabledWalletIds$.value.has(walletId))
|
|
249
|
+
throw new (0, _chunkNU46D4MZjs.KheopskitError)(
|
|
250
|
+
"WALLET_ALREADY_CONNECTED",
|
|
251
|
+
`wallet ${walletId} is already connected`,
|
|
252
|
+
{ walletId }
|
|
253
|
+
);
|
|
254
|
+
await provider.request({
|
|
255
|
+
method: "eth_requestAccounts"
|
|
256
|
+
});
|
|
257
|
+
const newSet = new Set(enabledWalletIds$.value);
|
|
258
|
+
newSet.add(walletId);
|
|
259
|
+
enabledWalletIds$.next(newSet);
|
|
260
|
+
store2.addEnabledWalletId(walletId);
|
|
261
|
+
};
|
|
262
|
+
const disconnectWallet = async (walletId) => {
|
|
263
|
+
if (!enabledWalletIds$.value.has(walletId))
|
|
264
|
+
throw new (0, _chunkNU46D4MZjs.KheopskitError)(
|
|
265
|
+
"WALLET_NOT_CONNECTED",
|
|
266
|
+
`wallet ${walletId} is not connected`,
|
|
267
|
+
{ walletId }
|
|
268
|
+
);
|
|
269
|
+
const newSet = new Set(enabledWalletIds$.value);
|
|
270
|
+
newSet.delete(walletId);
|
|
271
|
+
enabledWalletIds$.next(newSet);
|
|
272
|
+
store2.removeEnabledWalletId(walletId);
|
|
273
|
+
_chunkSIUWQBT4js.clearCachedObservable.call(void 0, `accounts:${walletId}`);
|
|
274
|
+
};
|
|
275
|
+
const sub = _rxjs.combineLatest.call(void 0, [providersDetails$, enabledWalletIds$]).pipe(
|
|
276
|
+
_rxjs.map.call(void 0, ([providerDetails, enabledWalletIds]) => {
|
|
277
|
+
return providerDetails.map((pd) => {
|
|
278
|
+
const walletId = _chunkSIUWQBT4js.getWalletId.call(void 0, "ethereum", pd.info.rdns);
|
|
279
|
+
const provider = pd.provider;
|
|
280
|
+
return {
|
|
281
|
+
platform: "ethereum",
|
|
282
|
+
type: "injected",
|
|
283
|
+
id: walletId,
|
|
284
|
+
name: pd.info.name,
|
|
285
|
+
icon: pd.info.icon,
|
|
286
|
+
provider,
|
|
287
|
+
isConnected: enabledWalletIds.has(walletId),
|
|
288
|
+
sourceId: pd.info.rdns,
|
|
289
|
+
connect: () => connectWallet(walletId, provider),
|
|
290
|
+
disconnect: () => disconnectWallet(walletId)
|
|
291
|
+
};
|
|
292
|
+
});
|
|
293
|
+
}),
|
|
294
|
+
_rxjs.distinctUntilChanged.call(void 0, walletsEqual)
|
|
295
|
+
).subscribe(subscriber);
|
|
296
|
+
return () => {
|
|
297
|
+
sub.unsubscribe();
|
|
298
|
+
};
|
|
299
|
+
}).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }));
|
|
300
|
+
var getEthereumWallets$ = (config, store2 = _chunkNU46D4MZjs.store) => {
|
|
301
|
+
return new (0, _rxjs.Observable)((subscriber) => {
|
|
302
|
+
const subscription = _rxjs.combineLatest.call(void 0, [
|
|
303
|
+
createEthereumInjectedWallets$(store2),
|
|
304
|
+
_chunkNU46D4MZjs.getAppKitWallets$.call(void 0, config).pipe(_rxjs.map.call(void 0, (w) => w.ethereum))
|
|
305
|
+
]).pipe(
|
|
306
|
+
_rxjs.map.call(void 0,
|
|
307
|
+
([injectedWallets, appKitWallet]) => appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets
|
|
308
|
+
)
|
|
309
|
+
).subscribe(subscriber);
|
|
310
|
+
return () => {
|
|
311
|
+
subscription.unsubscribe();
|
|
312
|
+
};
|
|
313
|
+
}).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }));
|
|
314
|
+
};
|
|
315
|
+
var walletsEqual = (a, b) => {
|
|
316
|
+
if (a.length !== b.length) return false;
|
|
317
|
+
return a.every(
|
|
318
|
+
(w, i) => w.id === _optionalChain([b, 'access', _17 => _17[i], 'optionalAccess', _18 => _18.id]) && w.isConnected === _optionalChain([b, 'access', _19 => _19[i], 'optionalAccess', _20 => _20.isConnected]) && w.name === _optionalChain([b, 'access', _21 => _21[i], 'optionalAccess', _22 => _22.name])
|
|
319
|
+
);
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// src/api/ethereum/plugin.ts
|
|
323
|
+
var ethereum = () => ({
|
|
324
|
+
platform: "ethereum",
|
|
325
|
+
getWallets$: (ctx) => getEthereumWallets$(ctx.config, ctx.store),
|
|
326
|
+
getAccounts$: (wallets$) => getEthereumAccounts$(wallets$)
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
exports.ethereum = ethereum; exports.isEthereumAddress = _chunkNU46D4MZjs.isEthereumAddress;
|
|
332
|
+
//# sourceMappingURL=ethereum.js.map
|