@cfxdevkit/core 0.1.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE +72 -0
  3. package/README.md +257 -0
  4. package/dist/clients/index.cjs +2053 -0
  5. package/dist/clients/index.cjs.map +1 -0
  6. package/dist/clients/index.d.cts +7 -0
  7. package/dist/clients/index.d.ts +7 -0
  8. package/dist/clients/index.js +2043 -0
  9. package/dist/clients/index.js.map +1 -0
  10. package/dist/config/index.cjs +423 -0
  11. package/dist/config/index.cjs.map +1 -0
  12. package/dist/config/index.d.cts +99 -0
  13. package/dist/config/index.d.ts +99 -0
  14. package/dist/config/index.js +380 -0
  15. package/dist/config/index.js.map +1 -0
  16. package/dist/config-BMtaWM0X.d.cts +165 -0
  17. package/dist/config-BMtaWM0X.d.ts +165 -0
  18. package/dist/core-C5qe16RS.d.ts +352 -0
  19. package/dist/core-RZA4aKwj.d.cts +352 -0
  20. package/dist/index-BhCpy6Fz.d.cts +165 -0
  21. package/dist/index-Qz84U9Oq.d.ts +165 -0
  22. package/dist/index.cjs +3773 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.d.cts +945 -0
  25. package/dist/index.d.ts +945 -0
  26. package/dist/index.js +3730 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/types/index.cjs +44 -0
  29. package/dist/types/index.cjs.map +1 -0
  30. package/dist/types/index.d.cts +5 -0
  31. package/dist/types/index.d.ts +5 -0
  32. package/dist/types/index.js +17 -0
  33. package/dist/types/index.js.map +1 -0
  34. package/dist/utils/index.cjs +83 -0
  35. package/dist/utils/index.cjs.map +1 -0
  36. package/dist/utils/index.d.cts +11 -0
  37. package/dist/utils/index.d.ts +11 -0
  38. package/dist/utils/index.js +56 -0
  39. package/dist/utils/index.js.map +1 -0
  40. package/dist/wallet/index.cjs +852 -0
  41. package/dist/wallet/index.cjs.map +1 -0
  42. package/dist/wallet/index.d.cts +726 -0
  43. package/dist/wallet/index.d.ts +726 -0
  44. package/dist/wallet/index.js +815 -0
  45. package/dist/wallet/index.js.map +1 -0
  46. package/package.json +119 -0
@@ -0,0 +1,380 @@
1
+ // src/config/chains.ts
2
+ import { defineChain } from "cive/utils";
3
+ import { defineChain as defineEvmChain } from "viem";
4
+ var CORE_MAINNET = {
5
+ id: 1029,
6
+ name: "conflux-core",
7
+ type: "core",
8
+ testnet: false,
9
+ nativeCurrency: {
10
+ name: "Conflux",
11
+ symbol: "CFX",
12
+ decimals: 18
13
+ },
14
+ rpcUrls: {
15
+ default: {
16
+ http: ["https://main.confluxrpc.com"],
17
+ webSocket: ["wss://main.confluxrpc.com/ws"]
18
+ }
19
+ },
20
+ blockExplorers: {
21
+ default: {
22
+ name: "ConfluxScan",
23
+ url: "https://confluxscan.io"
24
+ }
25
+ }
26
+ };
27
+ var CORE_TESTNET = {
28
+ id: 1,
29
+ name: "conflux-core-testnet",
30
+ type: "core",
31
+ testnet: true,
32
+ nativeCurrency: {
33
+ name: "Conflux",
34
+ symbol: "CFX",
35
+ decimals: 18
36
+ },
37
+ rpcUrls: {
38
+ default: {
39
+ http: ["https://test.confluxrpc.com"],
40
+ webSocket: ["wss://test.confluxrpc.com/ws"]
41
+ }
42
+ },
43
+ blockExplorers: {
44
+ default: {
45
+ name: "ConfluxScan Testnet",
46
+ url: "https://testnet.confluxscan.io"
47
+ }
48
+ }
49
+ };
50
+ var CORE_LOCAL = {
51
+ id: 2029,
52
+ name: "conflux-core-local",
53
+ type: "core",
54
+ testnet: true,
55
+ nativeCurrency: {
56
+ name: "Conflux",
57
+ symbol: "CFX",
58
+ decimals: 18
59
+ },
60
+ rpcUrls: {
61
+ default: {
62
+ http: ["http://localhost:12537"],
63
+ webSocket: ["ws://localhost:12536"]
64
+ }
65
+ }
66
+ };
67
+ var EVM_MAINNET = {
68
+ id: 1030,
69
+ name: "conflux-espace",
70
+ type: "evm",
71
+ testnet: false,
72
+ nativeCurrency: {
73
+ name: "Conflux",
74
+ symbol: "CFX",
75
+ decimals: 18
76
+ },
77
+ rpcUrls: {
78
+ default: {
79
+ http: ["https://evm.confluxrpc.com"]
80
+ }
81
+ },
82
+ blockExplorers: {
83
+ default: {
84
+ name: "ConfluxScan eSpace",
85
+ url: "https://evm.confluxscan.net"
86
+ }
87
+ },
88
+ contracts: {
89
+ multicall3: {
90
+ address: "0xcA11bde05977b3631167028862bE2a173976CA11",
91
+ blockCreated: 62512243
92
+ }
93
+ }
94
+ };
95
+ var EVM_TESTNET = {
96
+ id: 71,
97
+ name: "conflux-espace-testnet",
98
+ type: "evm",
99
+ testnet: true,
100
+ nativeCurrency: {
101
+ name: "Conflux",
102
+ symbol: "CFX",
103
+ decimals: 18
104
+ },
105
+ rpcUrls: {
106
+ default: {
107
+ http: ["https://evmtestnet.confluxrpc.com"]
108
+ }
109
+ },
110
+ blockExplorers: {
111
+ default: {
112
+ name: "ConfluxScan eSpace Testnet",
113
+ url: "https://evmtestnet.confluxscan.net"
114
+ }
115
+ },
116
+ contracts: {
117
+ multicall3: {
118
+ address: "0xcA11bde05977b3631167028862bE2a173976CA11",
119
+ blockCreated: 117499050
120
+ }
121
+ }
122
+ };
123
+ var EVM_LOCAL = {
124
+ id: 2030,
125
+ name: "conflux-espace-local",
126
+ type: "evm",
127
+ testnet: true,
128
+ nativeCurrency: {
129
+ name: "Conflux",
130
+ symbol: "CFX",
131
+ decimals: 18
132
+ },
133
+ rpcUrls: {
134
+ default: {
135
+ http: ["http://localhost:8545"]
136
+ }
137
+ }
138
+ };
139
+ var SUPPORTED_CHAINS = {
140
+ 1029: CORE_MAINNET,
141
+ 1: CORE_TESTNET,
142
+ 2029: CORE_LOCAL,
143
+ 1030: EVM_MAINNET,
144
+ 71: EVM_TESTNET,
145
+ 2030: EVM_LOCAL
146
+ };
147
+ function getChainConfig(chainId) {
148
+ const config = SUPPORTED_CHAINS[chainId];
149
+ if (!config) {
150
+ throw new Error(`Unsupported chain ID: ${chainId}`);
151
+ }
152
+ return config;
153
+ }
154
+ function isValidChainId(chainId) {
155
+ return chainId in SUPPORTED_CHAINS;
156
+ }
157
+ function getCoreChains() {
158
+ return Object.values(SUPPORTED_CHAINS).filter(
159
+ (chain) => chain.type === "core"
160
+ );
161
+ }
162
+ function getEvmChains() {
163
+ return Object.values(SUPPORTED_CHAINS).filter(
164
+ (chain) => chain.type === "evm"
165
+ );
166
+ }
167
+ function getMainnetChains() {
168
+ return Object.values(SUPPORTED_CHAINS).filter((chain) => !chain.testnet);
169
+ }
170
+ function getTestnetChains() {
171
+ return Object.values(SUPPORTED_CHAINS).filter((chain) => chain.testnet);
172
+ }
173
+ function toCiveChain(config) {
174
+ if (config.type !== "core") {
175
+ throw new Error(`Cannot convert ${config.type} chain to Cive chain`);
176
+ }
177
+ return defineChain({
178
+ id: config.id,
179
+ name: config.name,
180
+ nativeCurrency: config.nativeCurrency,
181
+ rpcUrls: config.rpcUrls,
182
+ blockExplorers: config.blockExplorers
183
+ });
184
+ }
185
+ function toViemChain(config) {
186
+ if (config.type !== "evm") {
187
+ throw new Error(`Cannot convert ${config.type} chain to Viem chain`);
188
+ }
189
+ return defineEvmChain({
190
+ id: config.id,
191
+ name: config.name,
192
+ nativeCurrency: config.nativeCurrency,
193
+ rpcUrls: config.rpcUrls,
194
+ blockExplorers: config.blockExplorers,
195
+ contracts: config.contracts
196
+ });
197
+ }
198
+ var NetworkSelector = class {
199
+ currentChainId;
200
+ previousChainId = null;
201
+ listeners = /* @__PURE__ */ new Set();
202
+ nodeRunningListeners = /* @__PURE__ */ new Set();
203
+ isNodeRunning = false;
204
+ lockedToLocal = false;
205
+ constructor(initialChainId = 1) {
206
+ this.currentChainId = initialChainId;
207
+ }
208
+ getCurrentChain() {
209
+ return getChainConfig(this.currentChainId);
210
+ }
211
+ getCurrentChainId() {
212
+ return this.currentChainId;
213
+ }
214
+ /**
215
+ * Switch to a specific chain
216
+ * @param chainId - Chain ID to switch to
217
+ * @param force - Force switch even if node is running (for wallet operations)
218
+ */
219
+ switchChain(chainId, force = false) {
220
+ if (!isValidChainId(chainId)) {
221
+ throw new Error(`Invalid chain ID: ${chainId}`);
222
+ }
223
+ if (this.isNodeRunning && !this.isLocalChain(chainId) && !force) {
224
+ console.warn(
225
+ `Cannot switch to chain ${chainId} while local node is running. Use force=true for wallet operations.`
226
+ );
227
+ return;
228
+ }
229
+ if (this.currentChainId !== chainId) {
230
+ this.currentChainId = chainId;
231
+ this.notifyListeners();
232
+ }
233
+ }
234
+ /**
235
+ * Called when local node starts - automatically switches to local chains
236
+ */
237
+ onNodeStart(coreChainId = 2029, evmChainId = 2030) {
238
+ if (!this.isNodeRunning) {
239
+ if (!this.isLocal()) {
240
+ this.previousChainId = this.currentChainId;
241
+ }
242
+ this.isNodeRunning = true;
243
+ this.lockedToLocal = true;
244
+ const targetLocalChain = this.isEvm() ? evmChainId : coreChainId;
245
+ this.switchChain(targetLocalChain, true);
246
+ this.notifyNodeRunningListeners();
247
+ }
248
+ }
249
+ /**
250
+ * Called when local node stops - can restore previous chain
251
+ */
252
+ onNodeStop(restorePrevious = true) {
253
+ if (this.isNodeRunning) {
254
+ this.isNodeRunning = false;
255
+ this.lockedToLocal = false;
256
+ if (restorePrevious && this.previousChainId) {
257
+ this.switchChain(this.previousChainId, true);
258
+ this.previousChainId = null;
259
+ }
260
+ this.notifyNodeRunningListeners();
261
+ }
262
+ }
263
+ /**
264
+ * Check if node is currently running
265
+ */
266
+ getNodeRunningStatus() {
267
+ return this.isNodeRunning;
268
+ }
269
+ /**
270
+ * Check if selector is locked to local chains
271
+ */
272
+ isLockedToLocal() {
273
+ return this.lockedToLocal;
274
+ }
275
+ onChainChange(listener) {
276
+ this.listeners.add(listener);
277
+ return () => this.listeners.delete(listener);
278
+ }
279
+ onNodeRunningChange(listener) {
280
+ this.nodeRunningListeners.add(listener);
281
+ return () => this.nodeRunningListeners.delete(listener);
282
+ }
283
+ notifyListeners() {
284
+ for (const listener of this.listeners) {
285
+ try {
286
+ listener(this.currentChainId);
287
+ } catch (error) {
288
+ console.error("Error in chain change listener:", error);
289
+ }
290
+ }
291
+ }
292
+ notifyNodeRunningListeners() {
293
+ for (const listener of this.nodeRunningListeners) {
294
+ try {
295
+ listener(this.isNodeRunning);
296
+ } catch (error) {
297
+ console.error("Error in node running listener:", error);
298
+ }
299
+ }
300
+ }
301
+ isLocalChain(chainId) {
302
+ return chainId === 2029 || chainId === 2030;
303
+ }
304
+ // Helper methods for chain type detection
305
+ isCore() {
306
+ return this.getCurrentChain().type === "core";
307
+ }
308
+ isEvm() {
309
+ return this.getCurrentChain().type === "evm";
310
+ }
311
+ isTestnet() {
312
+ return this.getCurrentChain().testnet;
313
+ }
314
+ isLocal() {
315
+ return this.currentChainId === 2029 || this.currentChainId === 2030;
316
+ }
317
+ // Get corresponding chain IDs
318
+ getCorrespondingChainId() {
319
+ switch (this.currentChainId) {
320
+ case 1029:
321
+ return 1030;
322
+ // Core mainnet -> eSpace mainnet
323
+ case 1030:
324
+ return 1029;
325
+ // eSpace mainnet -> Core mainnet
326
+ case 1:
327
+ return 71;
328
+ // Core testnet -> eSpace testnet
329
+ case 71:
330
+ return 1;
331
+ // eSpace testnet -> Core testnet
332
+ case 2029:
333
+ return 2030;
334
+ // Core local -> eSpace local
335
+ case 2030:
336
+ return 2029;
337
+ // eSpace local -> Core local
338
+ default:
339
+ return null;
340
+ }
341
+ }
342
+ /**
343
+ * Update local chain configurations with actual node URLs
344
+ * Called when ServerManager starts with specific ports
345
+ */
346
+ updateLocalChainUrls(coreRpcPort, evmRpcPort, wsPort) {
347
+ const coreLocal = SUPPORTED_CHAINS[2029];
348
+ if (coreLocal) {
349
+ coreLocal.rpcUrls.default.http = [`http://localhost:${coreRpcPort}`];
350
+ if (wsPort) {
351
+ coreLocal.rpcUrls.default.webSocket = [`ws://localhost:${wsPort}`];
352
+ }
353
+ }
354
+ const evmLocal = SUPPORTED_CHAINS[2030];
355
+ if (evmLocal) {
356
+ evmLocal.rpcUrls.default.http = [`http://localhost:${evmRpcPort}`];
357
+ }
358
+ }
359
+ };
360
+ var defaultNetworkSelector = new NetworkSelector();
361
+ export {
362
+ CORE_LOCAL,
363
+ CORE_MAINNET,
364
+ CORE_TESTNET,
365
+ EVM_LOCAL,
366
+ EVM_MAINNET,
367
+ EVM_TESTNET,
368
+ NetworkSelector,
369
+ SUPPORTED_CHAINS,
370
+ defaultNetworkSelector,
371
+ getChainConfig,
372
+ getCoreChains,
373
+ getEvmChains,
374
+ getMainnetChains,
375
+ getTestnetChains,
376
+ isValidChainId,
377
+ toCiveChain,
378
+ toViemChain
379
+ };
380
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config/chains.ts"],"sourcesContent":["/*\n * Copyright 2025 Conflux DevKit Team\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Centralized Chain Configuration\n// Matches Hardhat configuration with consistent naming across all clients\n\nimport type { Chain as CiveChain } from 'cive';\nimport { defineChain } from 'cive/utils';\nimport type { Chain as ViemChain } from 'viem';\nimport { defineChain as defineEvmChain } from 'viem';\n\nexport type SupportedChainId = 1029 | 1 | 2029 | 1030 | 71 | 2030;\n\nexport interface ChainConfig {\n id: SupportedChainId;\n name: string;\n type: 'core' | 'evm';\n testnet: boolean;\n nativeCurrency: {\n name: string;\n symbol: string;\n decimals: number;\n };\n rpcUrls: {\n default: {\n http: string[];\n webSocket?: string[];\n };\n };\n blockExplorers?: {\n default: {\n name: string;\n url: string;\n };\n };\n contracts?: {\n multicall3?: {\n address: `0x${string}`;\n blockCreated?: number;\n };\n };\n}\n\n// Core Space Chains (Conflux Protocol)\nexport const CORE_MAINNET: ChainConfig = {\n id: 1029,\n name: 'conflux-core',\n type: 'core',\n testnet: false,\n nativeCurrency: {\n name: 'Conflux',\n symbol: 'CFX',\n decimals: 18,\n },\n rpcUrls: {\n default: {\n http: ['https://main.confluxrpc.com'],\n webSocket: ['wss://main.confluxrpc.com/ws'],\n },\n },\n blockExplorers: {\n default: {\n name: 'ConfluxScan',\n url: 'https://confluxscan.io',\n },\n },\n};\n\nexport const CORE_TESTNET: ChainConfig = {\n id: 1,\n name: 'conflux-core-testnet',\n type: 'core',\n testnet: true,\n nativeCurrency: {\n name: 'Conflux',\n symbol: 'CFX',\n decimals: 18,\n },\n rpcUrls: {\n default: {\n http: ['https://test.confluxrpc.com'],\n webSocket: ['wss://test.confluxrpc.com/ws'],\n },\n },\n blockExplorers: {\n default: {\n name: 'ConfluxScan Testnet',\n url: 'https://testnet.confluxscan.io',\n },\n },\n};\n\nexport const CORE_LOCAL: ChainConfig = {\n id: 2029,\n name: 'conflux-core-local',\n type: 'core',\n testnet: true,\n nativeCurrency: {\n name: 'Conflux',\n symbol: 'CFX',\n decimals: 18,\n },\n rpcUrls: {\n default: {\n http: ['http://localhost:12537'],\n webSocket: ['ws://localhost:12536'],\n },\n },\n};\n\n// EVM Space Chains (Ethereum Compatible)\nexport const EVM_MAINNET: ChainConfig = {\n id: 1030,\n name: 'conflux-espace',\n type: 'evm',\n testnet: false,\n nativeCurrency: {\n name: 'Conflux',\n symbol: 'CFX',\n decimals: 18,\n },\n rpcUrls: {\n default: {\n http: ['https://evm.confluxrpc.com'],\n },\n },\n blockExplorers: {\n default: {\n name: 'ConfluxScan eSpace',\n url: 'https://evm.confluxscan.net',\n },\n },\n contracts: {\n multicall3: {\n address: '0xcA11bde05977b3631167028862bE2a173976CA11',\n blockCreated: 62512243,\n },\n },\n};\n\nexport const EVM_TESTNET: ChainConfig = {\n id: 71,\n name: 'conflux-espace-testnet',\n type: 'evm',\n testnet: true,\n nativeCurrency: {\n name: 'Conflux',\n symbol: 'CFX',\n decimals: 18,\n },\n rpcUrls: {\n default: {\n http: ['https://evmtestnet.confluxrpc.com'],\n },\n },\n blockExplorers: {\n default: {\n name: 'ConfluxScan eSpace Testnet',\n url: 'https://evmtestnet.confluxscan.net',\n },\n },\n contracts: {\n multicall3: {\n address: '0xcA11bde05977b3631167028862bE2a173976CA11',\n blockCreated: 117499050,\n },\n },\n};\n\nexport const EVM_LOCAL: ChainConfig = {\n id: 2030,\n name: 'conflux-espace-local',\n type: 'evm',\n testnet: true,\n nativeCurrency: {\n name: 'Conflux',\n symbol: 'CFX',\n decimals: 18,\n },\n rpcUrls: {\n default: {\n http: ['http://localhost:8545'],\n },\n },\n};\n\n// All supported chains\nexport const SUPPORTED_CHAINS: Record<SupportedChainId, ChainConfig> = {\n 1029: CORE_MAINNET,\n 1: CORE_TESTNET,\n 2029: CORE_LOCAL,\n 1030: EVM_MAINNET,\n 71: EVM_TESTNET,\n 2030: EVM_LOCAL,\n};\n\n// Chain utilities\nexport function getChainConfig(chainId: SupportedChainId): ChainConfig {\n const config = SUPPORTED_CHAINS[chainId];\n if (!config) {\n throw new Error(`Unsupported chain ID: ${chainId}`);\n }\n return config;\n}\n\nexport function isValidChainId(chainId: number): chainId is SupportedChainId {\n return chainId in SUPPORTED_CHAINS;\n}\n\nexport function getCoreChains(): ChainConfig[] {\n return Object.values(SUPPORTED_CHAINS).filter(\n (chain) => chain.type === 'core'\n );\n}\n\nexport function getEvmChains(): ChainConfig[] {\n return Object.values(SUPPORTED_CHAINS).filter(\n (chain) => chain.type === 'evm'\n );\n}\n\nexport function getMainnetChains(): ChainConfig[] {\n return Object.values(SUPPORTED_CHAINS).filter((chain) => !chain.testnet);\n}\n\nexport function getTestnetChains(): ChainConfig[] {\n return Object.values(SUPPORTED_CHAINS).filter((chain) => chain.testnet);\n}\n\n// Convert to native chain objects\nexport function toCiveChain(config: ChainConfig): CiveChain {\n if (config.type !== 'core') {\n throw new Error(`Cannot convert ${config.type} chain to Cive chain`);\n }\n\n return defineChain({\n id: config.id,\n name: config.name,\n nativeCurrency: config.nativeCurrency,\n rpcUrls: config.rpcUrls,\n blockExplorers: config.blockExplorers,\n });\n}\n\nexport function toViemChain(config: ChainConfig): ViemChain {\n if (config.type !== 'evm') {\n throw new Error(`Cannot convert ${config.type} chain to Viem chain`);\n }\n\n return defineEvmChain({\n id: config.id,\n name: config.name,\n nativeCurrency: config.nativeCurrency,\n rpcUrls: config.rpcUrls,\n blockExplorers: config.blockExplorers,\n contracts: config.contracts,\n });\n}\n\n// Network selector utility with automatic local switching\nexport class NetworkSelector {\n private currentChainId: SupportedChainId;\n private previousChainId: SupportedChainId | null = null;\n private listeners: Set<(chainId: SupportedChainId) => void> = new Set();\n private nodeRunningListeners: Set<(isRunning: boolean) => void> = new Set();\n private isNodeRunning = false;\n private lockedToLocal = false;\n\n constructor(initialChainId: SupportedChainId = 1) {\n this.currentChainId = initialChainId;\n }\n\n getCurrentChain(): ChainConfig {\n return getChainConfig(this.currentChainId);\n }\n\n getCurrentChainId(): SupportedChainId {\n return this.currentChainId;\n }\n\n /**\n * Switch to a specific chain\n * @param chainId - Chain ID to switch to\n * @param force - Force switch even if node is running (for wallet operations)\n */\n switchChain(chainId: SupportedChainId, force = false): void {\n if (!isValidChainId(chainId)) {\n throw new Error(`Invalid chain ID: ${chainId}`);\n }\n\n // If node is running and we're trying to switch to non-local, only allow if forced\n if (this.isNodeRunning && !this.isLocalChain(chainId) && !force) {\n console.warn(\n `Cannot switch to chain ${chainId} while local node is running. Use force=true for wallet operations.`\n );\n return;\n }\n\n if (this.currentChainId !== chainId) {\n this.currentChainId = chainId;\n this.notifyListeners();\n }\n }\n\n /**\n * Called when local node starts - automatically switches to local chains\n */\n onNodeStart(\n coreChainId: SupportedChainId = 2029,\n evmChainId: SupportedChainId = 2030\n ): void {\n if (!this.isNodeRunning) {\n // Store previous chain for restoration later\n if (!this.isLocal()) {\n this.previousChainId = this.currentChainId;\n }\n\n this.isNodeRunning = true;\n this.lockedToLocal = true;\n\n // Switch to appropriate local chain based on current chain type\n const targetLocalChain = this.isEvm() ? evmChainId : coreChainId;\n this.switchChain(targetLocalChain, true); // Force switch to local\n\n // Notify node running listeners\n this.notifyNodeRunningListeners();\n }\n }\n\n /**\n * Called when local node stops - can restore previous chain\n */\n onNodeStop(restorePrevious = true): void {\n if (this.isNodeRunning) {\n this.isNodeRunning = false;\n this.lockedToLocal = false;\n\n // Restore previous chain if requested and available\n if (restorePrevious && this.previousChainId) {\n this.switchChain(this.previousChainId, true);\n this.previousChainId = null;\n }\n\n // Notify node running listeners\n this.notifyNodeRunningListeners();\n }\n }\n\n /**\n * Check if node is currently running\n */\n getNodeRunningStatus(): boolean {\n return this.isNodeRunning;\n }\n\n /**\n * Check if selector is locked to local chains\n */\n isLockedToLocal(): boolean {\n return this.lockedToLocal;\n }\n\n onChainChange(listener: (chainId: SupportedChainId) => void): () => void {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n }\n\n onNodeRunningChange(listener: (isRunning: boolean) => void): () => void {\n this.nodeRunningListeners.add(listener);\n return () => this.nodeRunningListeners.delete(listener);\n }\n\n private notifyListeners(): void {\n for (const listener of this.listeners) {\n try {\n listener(this.currentChainId);\n } catch (error) {\n console.error('Error in chain change listener:', error);\n }\n }\n }\n\n private notifyNodeRunningListeners(): void {\n for (const listener of this.nodeRunningListeners) {\n try {\n listener(this.isNodeRunning);\n } catch (error) {\n console.error('Error in node running listener:', error);\n }\n }\n }\n\n private isLocalChain(chainId: SupportedChainId): boolean {\n return chainId === 2029 || chainId === 2030;\n }\n\n // Helper methods for chain type detection\n isCore(): boolean {\n return this.getCurrentChain().type === 'core';\n }\n\n isEvm(): boolean {\n return this.getCurrentChain().type === 'evm';\n }\n\n isTestnet(): boolean {\n return this.getCurrentChain().testnet;\n }\n\n isLocal(): boolean {\n return this.currentChainId === 2029 || this.currentChainId === 2030;\n }\n\n // Get corresponding chain IDs\n getCorrespondingChainId(): SupportedChainId | null {\n switch (this.currentChainId) {\n case 1029:\n return 1030; // Core mainnet -> eSpace mainnet\n case 1030:\n return 1029; // eSpace mainnet -> Core mainnet\n case 1:\n return 71; // Core testnet -> eSpace testnet\n case 71:\n return 1; // eSpace testnet -> Core testnet\n case 2029:\n return 2030; // Core local -> eSpace local\n case 2030:\n return 2029; // eSpace local -> Core local\n default:\n return null;\n }\n }\n\n /**\n * Update local chain configurations with actual node URLs\n * Called when ServerManager starts with specific ports\n */\n updateLocalChainUrls(\n coreRpcPort: number,\n evmRpcPort: number,\n wsPort?: number\n ): void {\n // Update Core local chain\n const coreLocal = SUPPORTED_CHAINS[2029];\n if (coreLocal) {\n coreLocal.rpcUrls.default.http = [`http://localhost:${coreRpcPort}`];\n if (wsPort) {\n coreLocal.rpcUrls.default.webSocket = [`ws://localhost:${wsPort}`];\n }\n }\n\n // Update eSpace local chain\n const evmLocal = SUPPORTED_CHAINS[2030];\n if (evmLocal) {\n evmLocal.rpcUrls.default.http = [`http://localhost:${evmRpcPort}`];\n }\n }\n}\n\n// Default network selector instance\nexport const defaultNetworkSelector = new NetworkSelector();\n"],"mappings":";AAoBA,SAAS,mBAAmB;AAE5B,SAAS,eAAe,sBAAsB;AAmCvC,IAAM,eAA4B;AAAA,EACvC,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,gBAAgB;AAAA,IACd,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,UAAU;AAAA,EACZ;AAAA,EACA,SAAS;AAAA,IACP,SAAS;AAAA,MACP,MAAM,CAAC,6BAA6B;AAAA,MACpC,WAAW,CAAC,8BAA8B;AAAA,IAC5C;AAAA,EACF;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,MAAM;AAAA,MACN,KAAK;AAAA,IACP;AAAA,EACF;AACF;AAEO,IAAM,eAA4B;AAAA,EACvC,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,gBAAgB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AAQ,QAAQ,OAAO,CAAC,oBAAoB,UAAU,EAAE;AAAA,IACnE;AAAA,EACF;AACF;AAGO,IAAM,yBAAyB,IAAI,gBAAgB;","names":[]}
@@ -0,0 +1,165 @@
1
+ interface NodeConfig {
2
+ readonly chainId?: number;
3
+ readonly evmChainId?: number;
4
+ readonly jsonrpcHttpPort?: number;
5
+ readonly jsonrpcHttpEthPort?: number;
6
+ readonly jsonrpcWsPort?: number;
7
+ readonly jsonrpcWsEthPort?: number;
8
+ readonly confluxDataDir?: string;
9
+ readonly log?: boolean;
10
+ readonly logConf?: string;
11
+ readonly genesisSecrets?: readonly string[];
12
+ readonly genesisEvmSecrets?: readonly string[];
13
+ readonly miningAuthor?: string;
14
+ readonly nodeType?: 'full' | 'archive' | 'light';
15
+ readonly blockDbType?: 'rocksdb' | 'sqlite';
16
+ }
17
+ interface ExtendedNodeConfig extends NodeConfig {
18
+ readonly accountCount?: number;
19
+ readonly silent?: boolean;
20
+ readonly fundAccounts?: boolean;
21
+ readonly enabledChains?: readonly ('core' | 'evm')[];
22
+ readonly derivationPaths?: {
23
+ readonly core: string;
24
+ readonly evm: string;
25
+ };
26
+ }
27
+ type Address = string;
28
+ type CoreAddress = string;
29
+ type EvmAddress = string;
30
+ type Hash = string;
31
+ type ChainType = 'core' | 'evm';
32
+ interface UnifiedAccount {
33
+ readonly id: string;
34
+ readonly name: string;
35
+ readonly index: number;
36
+ readonly privateKey: string;
37
+ readonly derivationPath: string;
38
+ readonly coreAddress: CoreAddress;
39
+ readonly evmAddress: EvmAddress;
40
+ readonly coreBalance: bigint;
41
+ readonly evmBalance: bigint;
42
+ readonly coreNonce: number;
43
+ readonly evmNonce: number;
44
+ readonly isActive: boolean;
45
+ readonly createdAt: Date;
46
+ readonly updatedAt: Date;
47
+ }
48
+ interface ChainStatus {
49
+ readonly isRunning: boolean;
50
+ readonly chainId: number;
51
+ readonly blockNumber: bigint;
52
+ readonly gasPrice: bigint;
53
+ readonly peerCount: number;
54
+ readonly syncStatus: 'syncing' | 'synced';
55
+ readonly latestBlockHash: string;
56
+ readonly mining: boolean;
57
+ readonly pendingTransactions: number;
58
+ readonly rpcEndpoint: string;
59
+ readonly wsEndpoint?: string;
60
+ }
61
+ interface NodeStatus {
62
+ readonly isRunning: boolean;
63
+ readonly uptime: number;
64
+ readonly startTime: Date | null;
65
+ readonly core: ChainStatus;
66
+ readonly evm: ChainStatus;
67
+ readonly dataDir: string;
68
+ readonly config: NodeConfig;
69
+ readonly mining: MiningStatus;
70
+ }
71
+ interface MiningStatus {
72
+ readonly isRunning: boolean;
73
+ readonly interval: number;
74
+ readonly blocksMined: number;
75
+ readonly startTime: Date | null;
76
+ readonly lastBlockTime: Date | null;
77
+ }
78
+ interface BaseTransaction {
79
+ readonly to?: string;
80
+ readonly value?: bigint;
81
+ readonly data?: string;
82
+ readonly gasLimit?: bigint;
83
+ readonly gasPrice?: bigint;
84
+ readonly nonce?: number;
85
+ }
86
+ interface TransactionReceipt {
87
+ readonly hash: string;
88
+ readonly blockNumber: bigint;
89
+ readonly blockHash: string;
90
+ readonly transactionIndex: number;
91
+ readonly status: 'success' | 'reverted';
92
+ readonly gasUsed: bigint;
93
+ readonly contractAddress?: string;
94
+ readonly logs: readonly Log[];
95
+ }
96
+ interface Log {
97
+ readonly address: string;
98
+ readonly topics: readonly string[];
99
+ readonly data: string;
100
+ readonly blockNumber: bigint;
101
+ readonly transactionHash: string;
102
+ readonly logIndex: number;
103
+ }
104
+ interface ConfluxNodeError extends Error {
105
+ readonly code: string;
106
+ readonly chain?: ChainType;
107
+ readonly context?: Record<string, unknown>;
108
+ }
109
+ declare class NodeError extends Error implements ConfluxNodeError {
110
+ readonly code: string;
111
+ readonly chain?: ChainType;
112
+ readonly context?: Record<string, unknown>;
113
+ constructor(message: string, code: string, chain?: ChainType, context?: Record<string, unknown>);
114
+ }
115
+ interface BlockEvent {
116
+ readonly chainType: ChainType;
117
+ readonly blockNumber: bigint;
118
+ readonly blockHash: string;
119
+ readonly timestamp: number;
120
+ readonly transactionCount: number;
121
+ }
122
+ interface TransactionEvent {
123
+ readonly chainType: ChainType;
124
+ readonly hash: string;
125
+ readonly from: string;
126
+ readonly to?: string;
127
+ readonly value: bigint;
128
+ readonly blockNumber: bigint;
129
+ }
130
+ type EventCallback<T> = (event: T) => void;
131
+ type UnwatchFunction = () => void;
132
+ type ServerStatus = 'stopped' | 'starting' | 'running' | 'stopping' | 'error';
133
+ interface ServerConfig {
134
+ readonly coreRpcPort?: number;
135
+ readonly evmRpcPort?: number;
136
+ readonly wsPort?: number;
137
+ readonly chainId?: number;
138
+ readonly evmChainId?: number;
139
+ readonly accounts?: number;
140
+ readonly balance?: string;
141
+ readonly mnemonic?: string;
142
+ readonly logging?: boolean;
143
+ readonly detached?: boolean;
144
+ readonly mining?: MiningConfig;
145
+ readonly devBlockIntervalMs?: number;
146
+ readonly devPackTxImmediately?: boolean;
147
+ readonly dataDir?: string;
148
+ }
149
+ interface MiningConfig {
150
+ readonly enabled: boolean;
151
+ readonly interval: number;
152
+ readonly autoStart: boolean;
153
+ }
154
+ interface AccountInfo {
155
+ readonly index: number;
156
+ readonly privateKey: string;
157
+ readonly coreAddress: string;
158
+ readonly evmAddress: string;
159
+ readonly mnemonic: string;
160
+ readonly path: string;
161
+ readonly evmPrivateKey?: string;
162
+ readonly evmPath?: string;
163
+ }
164
+
165
+ export { type Address as A, type BaseTransaction as B, type ChainType as C, type EventCallback as E, type Hash as H, type Log as L, type MiningConfig as M, type NodeConfig as N, type ServerConfig as S, type TransactionReceipt as T, type UnwatchFunction as U, type BlockEvent as a, type TransactionEvent as b, type AccountInfo as c, type ConfluxNodeError as d, type CoreAddress as e, type EvmAddress as f, type ExtendedNodeConfig as g, NodeError as h, type NodeStatus as i, type ServerStatus as j, type UnifiedAccount as k };