wative 1.1.15 → 1.1.17

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 (65) hide show
  1. package/lib/account.d.ts +14 -0
  2. package/lib/account.d.ts.map +1 -0
  3. package/lib/assets.d.ts +11 -0
  4. package/lib/assets.d.ts.map +1 -0
  5. package/lib/chain.d.ts +6 -0
  6. package/lib/chain.d.ts.map +1 -0
  7. package/lib/config.d.ts +23 -0
  8. package/lib/config.d.ts.map +1 -0
  9. package/lib/daemon-watcher.js +181 -0
  10. package/lib/home_page.d.ts +4 -0
  11. package/lib/home_page.d.ts.map +1 -0
  12. package/lib/index.d.ts +2 -0
  13. package/lib/index.d.ts.map +1 -0
  14. package/lib/index.esm.js +1 -1
  15. package/lib/index.umd.js +1 -1
  16. package/lib/network.d.ts +28 -0
  17. package/lib/network.d.ts.map +1 -0
  18. package/lib/ssh/client.d.ts +120 -0
  19. package/lib/ssh/client.d.ts.map +1 -0
  20. package/lib/ssh/client_example.d.ts +19 -0
  21. package/lib/ssh/client_example.d.ts.map +1 -0
  22. package/lib/ssh/client_test.d.ts +27 -0
  23. package/lib/ssh/client_test.d.ts.map +1 -0
  24. package/lib/ssh/config_manager.d.ts +55 -0
  25. package/lib/ssh/config_manager.d.ts.map +1 -0
  26. package/lib/ssh/config_template.d.ts +52 -0
  27. package/lib/ssh/config_template.d.ts.map +1 -0
  28. package/lib/ssh/index.d.ts +7 -0
  29. package/lib/ssh/index.d.ts.map +1 -0
  30. package/lib/ssh/remote_server_example.d.ts +16 -0
  31. package/lib/ssh/remote_server_example.d.ts.map +1 -0
  32. package/lib/ssh/service_manager.d.ts +119 -0
  33. package/lib/ssh/service_manager.d.ts.map +1 -0
  34. package/lib/ssh/types.d.ts +45 -0
  35. package/lib/ssh/types.d.ts.map +1 -0
  36. package/lib/ssh/utils.d.ts +11 -0
  37. package/lib/ssh/utils.d.ts.map +1 -0
  38. package/lib/ssh/wative_server.d.ts +26 -0
  39. package/lib/ssh/wative_server.d.ts.map +1 -0
  40. package/lib/tools.d.ts +6 -0
  41. package/lib/tools.d.ts.map +1 -0
  42. package/lib/tx_gas_utils.d.ts +18 -0
  43. package/lib/tx_gas_utils.d.ts.map +1 -0
  44. package/lib/utils.d.ts +49 -0
  45. package/lib/utils.d.ts.map +1 -0
  46. package/lib/wative.d.ts +2 -0
  47. package/lib/wative.d.ts.map +1 -0
  48. package/lib/wative.esm.js +1 -1
  49. package/lib/wative.umd.js +1 -1
  50. package/lib/web3.d.ts +59 -0
  51. package/lib/web3.d.ts.map +1 -0
  52. package/package.json +9 -5
  53. package/src/assets.ts +1 -10
  54. package/src/daemon-watcher.js +181 -0
  55. package/src/ssh/client.rs +221 -0
  56. package/src/ssh/client.ts +389 -0
  57. package/src/ssh/config_manager.ts +317 -0
  58. package/src/ssh/index.ts +49 -36
  59. package/src/ssh/service_manager.ts +684 -0
  60. package/src/ssh/types.ts +35 -1
  61. package/src/ssh/wative_server.ts +1 -2
  62. package/src/wative.ts +560 -122
  63. package/bin/wative-ssh.sh +0 -44
  64. package/lib/wative-ssh.esm.js +0 -1
  65. package/lib/wative-ssh.umd.js +0 -1
package/src/ssh/index.ts CHANGED
@@ -1,52 +1,65 @@
1
- import WativeServer from './wative_server';
2
- import * as path from 'path';
3
- import { getAndGenerateConfig } from './utils';
1
+ import { SSHServiceManager } from './service_manager';
2
+
3
+ // Export the new SSH client
4
+ export { WativeSSHClient, SSHConfig, createWativeSSHClient } from './client';
5
+ export { WativeWielderServer } from './wative_server';
6
+ export * from './types';
7
+ export * from './utils';
4
8
 
5
9
  require('dotenv').config();
6
- const os = require('os');
7
10
 
8
- const getKeystorePasswords = async (allowedKeystores: string[]) => {
9
- const passwords: any = [];
10
- for (let i = 0; i < allowedKeystores.length; i++) {
11
- const keystore = allowedKeystores[i].replace(/-/g, '_');
12
- passwords.push(process.env[keystore]);
13
- }
14
- return passwords;
15
- }
11
+ // 新的主函数,支持多配置文件
12
+ const mainWithConfig = async (configName?: string) => {
13
+ const serviceManager = new SSHServiceManager();
16
14
 
15
+ try {
16
+ // 配置名称是必需的
17
+ if (!configName) {
18
+ throw new Error('Configuration name is required. Please specify a configuration name.');
19
+ }
17
20
 
18
- const main = async () => {
19
- const userHomeDirectory = os.homedir();
20
- const keystorePath = path.join(userHomeDirectory, '.wative');
21
+ console.log(`Starting SSH service with configuration: ${configName}`);
22
+ await serviceManager.startService(configName);
21
23
 
22
- let config = await getAndGenerateConfig(keystorePath);
24
+ console.log('SSH service started successfully.');
23
25
 
24
- const export_server_listen = config.ssh.listen;
25
- const export_server_port = config.ssh.port;
26
- const id_rsa_private_key_path = "/etc/wative/id_rsa_server";
27
- const id_rsa_password = "wative_server";
26
+ // 保持进程运行
27
+ process.on('SIGINT', async () => {
28
+ console.log('\nShutting down SSH services...');
29
+ await serviceManager.stopAllServices();
30
+ process.exit(0);
31
+ });
28
32
 
29
- const client_name = 'detake';
30
- const client_id_rsa_public_key_path = "/etc/wative/id_rsa_detake.pub";
31
- const client_keystores = config.keystore.allowed_keystores;
32
- const client_keystore_passwords = await getKeystorePasswords(client_keystores);
33
+ process.on('SIGTERM', async () => {
34
+ console.log('\nShutting down SSH services...');
35
+ await serviceManager.stopAllServices();
36
+ process.exit(0);
37
+ });
38
+
39
+ } catch (error: any) {
40
+ console.error(`Failed to start SSH service: ${error.message}`);
41
+ process.exit(1);
42
+ }
43
+ };
33
44
 
34
- const wativeServer = new WativeServer(
35
- id_rsa_private_key_path,
36
- id_rsa_password,
37
- [client_name],
38
- [client_id_rsa_public_key_path],
39
- [client_keystores],
40
- keystorePath,
41
- client_keystores,
42
- client_keystore_passwords,
43
- );
45
+ // 检查命令行参数
46
+ const args = process.argv.slice(2);
47
+ const isDaemon = args.includes('--daemon');
48
+ const configIndex = args.indexOf('--config');
49
+ const configName = configIndex !== -1 && args[configIndex + 1] ? args[configIndex + 1] : undefined;
44
50
 
45
- wativeServer.listen(export_server_listen, export_server_port);
51
+ // 根据参数选择启动方式
52
+ if (isDaemon || configName) {
53
+ // 使用新的多配置文件方式
54
+ mainWithConfig(configName).catch(error => {
55
+ console.error('Failed to start SSH service:', error);
56
+ process.exit(1);
57
+ });
46
58
  }
47
59
 
48
60
  process.on('unhandledRejection', (reason, p) => {
49
61
  console.log('Unhandled Rejection at:', p, 'reason:', reason);
50
62
  });
51
63
 
52
- main()
64
+ // 导出函数供其他模块使用
65
+ export { mainWithConfig };