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
@@ -0,0 +1,14 @@
1
+ declare const WativeCore: any;
2
+ export declare const getNetworkInfo: (keystore_path: string) => any;
3
+ export declare const getAccountInfo: (keystore_path: string, keystore_slug: string) => any;
4
+ export declare const saveAccountInfo: (keystore_path: string, keystore_slug: string, account_info: any) => void;
5
+ export declare const loginIn: (keystore_path: string, keystore_slug: string, wative_core: typeof WativeCore) => Promise<{
6
+ isLoginIn: boolean;
7
+ password?: undefined;
8
+ } | {
9
+ isLoginIn: boolean;
10
+ password: any;
11
+ }>;
12
+ export declare const accountSetting: (keystore_path: string, wative_core: typeof WativeCore) => Promise<void>;
13
+ export {};
14
+ //# sourceMappingURL=account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAgCA,QAAA,MAAQ,UAAU,KAA2B,CAAC;AA8M9C,eAAO,MAAM,cAAc,GAAI,eAAe,MAAM,QAInD,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,eAAe,MAAM,EAAE,eAAe,MAAM,QAI1E,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,eAAe,MAAM,EAAE,eAAe,MAAM,EAAE,cAAc,GAAG,SAG9F,CAAA;AAED,eAAO,MAAM,OAAO,GAAU,eAAe,MAAM,EAAE,eAAe,MAAM,EAAE,aAAa,OAAO,UAAU;;;;;;EAyCzG,CAAA;AA6gBD,eAAO,MAAM,cAAc,GAAU,eAAe,MAAM,EAAE,aAAa,OAAO,UAAU,kBA0CzF,CAAA"}
@@ -0,0 +1,11 @@
1
+ export declare const getAssetList: (keystore_path: string, chain_id: string) => Promise<any>;
2
+ export declare const getAssetListByTokenName: (keystore_path: string, chain_id: string, token_name: string) => Promise<any>;
3
+ export declare const showAssetsDetail: (keystore_path: string, default_network: string, account_address: string) => Promise<void>;
4
+ export declare const updateTokenBalanceOption: (keystore_path: string, default_network: string, account_address: string) => Promise<void>;
5
+ export declare const saveAsset: (keystore_path: string, chain_id: string, asset_address: string, symbol: string, name: string, decimals: number, display_decimals: number) => Promise<void>;
6
+ export declare const addToken: (keystore_path: string) => Promise<void>;
7
+ export declare const addAsset: (keystore_path: string, default_network: string) => Promise<void>;
8
+ export declare const showAssets: (keystore_path: string, account_address: string, default_network: string) => Promise<void>;
9
+ export declare const batchGetTokenBalance: (account_address: string, asset_info_list: any, rpc_url: string, chain_type: string, chain_id: string) => Promise<any>;
10
+ export declare const getBatchAccountBalance: (keystore_path: string, account_address_list: string[], asset_info_list: any, rpc_url: string, network_name: string, show_gas_token: boolean, show_extended_token: boolean) => Promise<any>;
11
+ //# sourceMappingURL=assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,YAAY,GACrB,eAAe,MAAM,EACrB,UAAU,MAAM,iBAcnB,CAAA;AAED,eAAO,MAAM,uBAAuB,GAChC,eAAe,MAAM,EACrB,UAAU,MAAM,EAChB,YAAY,MAAM,iBAUrB,CAAA;AAED,eAAO,MAAM,gBAAgB,GACzB,eAAe,MAAM,EACrB,iBAAiB,MAAM,EACvB,iBAAiB,MAAM,kBAkC1B,CAAA;AAED,eAAO,MAAM,wBAAwB,GACjC,eAAe,MAAM,EACrB,iBAAiB,MAAM,EACvB,iBAAiB,MAAM,kBAO1B,CAAA;AAED,eAAO,MAAM,SAAS,GAClB,eAAe,MAAM,EACrB,UAAU,MAAM,EAChB,eAAe,MAAM,EACrB,QAAQ,MAAM,EACd,MAAM,MAAM,EACZ,UAAU,MAAM,EAChB,kBAAkB,MAAM,kBAsC3B,CAAA;AAED,eAAO,MAAM,QAAQ,GACjB,eAAe,MAAM,kBA2DxB,CAAA;AAED,eAAO,MAAM,QAAQ,GACjB,eAAe,MAAM,EACrB,iBAAiB,MAAM,kBAgD1B,CAAA;AAED,eAAO,MAAM,UAAU,GACnB,eAAe,MAAM,EACrB,iBAAiB,MAAM,EACvB,iBAAiB,MAAM,kBAyB1B,CAAA;AAED,eAAO,MAAM,oBAAoB,GAC7B,iBAAiB,MAAM,EACvB,iBAAiB,GAAG,EACpB,SAAS,MAAM,EACf,YAAY,MAAM,EAClB,UAAU,MAAM,iBAqDnB,CAAA;AAED,eAAO,MAAM,sBAAsB,GAC/B,eAAe,MAAM,EACrB,sBAAsB,MAAM,EAAE,EAC9B,iBAAiB,GAAG,EACpB,SAAS,MAAM,EACf,cAAc,MAAM,EACpB,gBAAgB,OAAO,EACvB,qBAAqB,OAAO,iBA4C/B,CAAA"}
package/lib/chain.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export declare const SOLANA_CHAIN_IDS: string[];
2
+ export declare const getNativeTokenDecimals: (chain_id: string) => 9 | 18;
3
+ export declare const getChainType: (chain_id: string) => "solana" | "evm";
4
+ export declare const isSolanaAddress: (account_address: string) => boolean;
5
+ export declare const isEvmAddress: (account_address: string) => boolean;
6
+ //# sourceMappingURL=chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,gBAAgB,UAAwB,CAAC;AAEtD,eAAO,MAAM,sBAAsB,GAAI,UAAU,MAAM,WAMtD,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM,qBAM5C,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,iBAAiB,MAAM,YAGtD,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,iBAAiB,MAAM,YAGnD,CAAA"}
@@ -0,0 +1,23 @@
1
+ export declare const MNEMONIC_WORDS: string[];
2
+ export declare const DEFAULT_NETWORK: ({
3
+ name: string;
4
+ chainId: number;
5
+ rpcUrl: string;
6
+ nativeCurrency: {
7
+ name: string;
8
+ symbol: string;
9
+ decimals: number;
10
+ };
11
+ multicallAddress: string;
12
+ } | {
13
+ name: string;
14
+ chainId: number;
15
+ rpcUrl: string;
16
+ nativeCurrency: {
17
+ name: string;
18
+ symbol: string;
19
+ decimals: number;
20
+ };
21
+ multicallAddress?: undefined;
22
+ })[];
23
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,UAigE1B,CAAA;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;IAsB3B,CAAA"}
@@ -0,0 +1,181 @@
1
+ const { spawn } = require('child_process');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const crypto = require('crypto');
5
+
6
+ // Get configuration from command line arguments
7
+ const serviceName = process.argv[2];
8
+ const logFile = process.argv[3];
9
+ const pidFile = process.argv[4];
10
+ const watcherPidFile = process.argv[5];
11
+ const wativeRoot = process.argv[6];
12
+
13
+ // Get encrypted passwords from environment variable and immediately delete it
14
+ const encryptedPasswords = process.env.WATIVE_ENCRYPTED_PASSWORDS;
15
+ delete process.env.WATIVE_ENCRYPTED_PASSWORDS;
16
+
17
+ if (!encryptedPasswords) {
18
+ console.error('Error: WATIVE_ENCRYPTED_PASSWORDS environment variable not found');
19
+ process.exit(1);
20
+ }
21
+
22
+ let childProcess = null;
23
+ let restartCount = 0;
24
+ const maxRestarts = 10;
25
+ const restartDelay = 5000; // 5 seconds
26
+
27
+ // Hash verification for wative.umd.js
28
+ let initialFileHash = null;
29
+ const wativeUmdPath = path.join(wativeRoot, 'lib', 'wative.umd.js');
30
+
31
+ /**
32
+ * Calculate SHA256 hash of a file
33
+ * @param {string} filePath - Path to the file
34
+ * @returns {string|null} - Hash string or null if file doesn't exist
35
+ */
36
+ const calculateFileHash = (filePath) => {
37
+ try {
38
+ if (!fs.existsSync(filePath)) {
39
+ return null;
40
+ }
41
+ const fileBuffer = fs.readFileSync(filePath);
42
+ const hashSum = crypto.createHash('sha256');
43
+ hashSum.update(fileBuffer);
44
+ return hashSum.digest('hex');
45
+ } catch (error) {
46
+ logToFile(`Error calculating file hash: ${error.message}`);
47
+ return null;
48
+ }
49
+ };
50
+
51
+ /**
52
+ * Verify if the current file hash matches the initial hash
53
+ * @returns {boolean} - True if hashes match or initial hash is not set
54
+ */
55
+ const verifyFileHash = () => {
56
+ if (!initialFileHash) {
57
+ return true; // No initial hash to compare against
58
+ }
59
+
60
+ const currentHash = calculateFileHash(wativeUmdPath);
61
+ if (!currentHash) {
62
+ logToFile(`Warning: Could not calculate current hash for ${wativeUmdPath}`);
63
+ return false;
64
+ }
65
+
66
+ const hashesMatch = currentHash === initialFileHash;
67
+ if (!hashesMatch) {
68
+ logToFile(`File hash mismatch detected!`);
69
+ logToFile(`Initial hash: ${initialFileHash}`);
70
+ logToFile(`Current hash: ${currentHash}`);
71
+ }
72
+
73
+ return hashesMatch;
74
+ };
75
+
76
+ /**
77
+ * Log message to daemon log file with timestamp
78
+ * @param {string} message - Message to log
79
+ */
80
+ const logToFile = (message) => {
81
+ const timestamp = new Date().toISOString();
82
+ const logMessage = `[${timestamp}] [WATCHER] ${message}\n`;
83
+ fs.appendFileSync(logFile, logMessage);
84
+ };
85
+
86
+ /**
87
+ * Start the SSH service process
88
+ */
89
+ const startService = () => {
90
+ if (restartCount >= maxRestarts) {
91
+ logToFile(`Maximum restart attempts (${maxRestarts}) reached. Stopping watcher.`);
92
+ process.exit(1);
93
+ }
94
+
95
+ // Initialize or verify file hash
96
+ if (initialFileHash === null) {
97
+ // First startup - calculate and store the initial hash
98
+ initialFileHash = calculateFileHash(wativeUmdPath);
99
+ if (initialFileHash) {
100
+ logToFile(`Initial file hash calculated: ${initialFileHash}`);
101
+ } else {
102
+ logToFile(`Warning: Could not calculate initial hash for ${wativeUmdPath}`);
103
+ }
104
+ } else {
105
+ // Restart - verify hash before proceeding
106
+ if (!verifyFileHash()) {
107
+ logToFile(`File integrity check failed. Exiting daemon to prevent potential security issues.`);
108
+ process.exit(1);
109
+ }
110
+ logToFile(`File integrity check passed.`);
111
+ }
112
+
113
+ logToFile(`Starting SSH service '${serviceName}' (attempt ${restartCount + 1})`);
114
+
115
+ // Spawn the SSH service process
116
+ childProcess = spawn('npx', ['ts-node', path.join(wativeRoot, 'src', 'wative.ts'), 'ssh', 'start', '-c', serviceName], {
117
+ stdio: ['ignore', fs.openSync(logFile, 'a'), fs.openSync(logFile, 'a')],
118
+ env: {
119
+ ...process.env,
120
+ WATIVE_DAEMON_PASSWORDS: encryptedPasswords,
121
+ WATIVE_WORKER_MODE: 'true'
122
+ },
123
+ cwd: wativeRoot
124
+ });
125
+
126
+ // Write service PID to file
127
+ fs.writeFileSync(pidFile, childProcess.pid.toString());
128
+
129
+ // Handle service process exit
130
+ childProcess.on('exit', (code, signal) => {
131
+ logToFile(`SSH service exited with code ${code}, signal ${signal}`);
132
+
133
+ // Check if service crashed (non-zero exit code and not terminated by user)
134
+ if (code !== 0 && signal !== 'SIGTERM' && signal !== 'SIGINT') {
135
+ restartCount++;
136
+ logToFile(`Service crashed. Restarting in ${restartDelay/1000} seconds...`);
137
+ setTimeout(startService, restartDelay);
138
+ } else {
139
+ logToFile('Service stopped normally.');
140
+ // Clean up PID files
141
+ try {
142
+ fs.unlinkSync(pidFile);
143
+ fs.unlinkSync(watcherPidFile);
144
+ } catch (e) {
145
+ // Ignore cleanup errors
146
+ }
147
+ process.exit(0);
148
+ }
149
+ });
150
+
151
+ // Handle service process errors
152
+ childProcess.on('error', (error) => {
153
+ logToFile(`Failed to start service: ${error.message}`);
154
+ restartCount++;
155
+ setTimeout(startService, restartDelay);
156
+ });
157
+ };
158
+
159
+ /**
160
+ * Handle graceful shutdown signals
161
+ * @param {string} signal - Signal received
162
+ */
163
+ const gracefulShutdown = (signal) => {
164
+ logToFile(`Watcher received ${signal}, stopping service...`);
165
+ if (childProcess) {
166
+ childProcess.kill('SIGTERM');
167
+ // Force kill after 5 seconds if process doesn't terminate gracefully
168
+ setTimeout(() => {
169
+ if (childProcess && !childProcess.killed) {
170
+ childProcess.kill('SIGKILL');
171
+ }
172
+ }, 5000);
173
+ }
174
+ };
175
+
176
+ // Register signal handlers for graceful shutdown
177
+ process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));
178
+ process.on('SIGINT', () => gracefulShutdown('SIGINT'));
179
+
180
+ // Start the service
181
+ startService();
@@ -0,0 +1,4 @@
1
+ declare const WativeCore: any;
2
+ export declare const showHomePage: (keystore_path: string, wative_core: typeof WativeCore) => Promise<void>;
3
+ export {};
4
+ //# sourceMappingURL=home_page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"home_page.d.ts","sourceRoot":"","sources":["../src/home_page.ts"],"names":[],"mappings":"AAIA,QAAA,MAAQ,UAAU,KAA2B,CAAC;AAE9C,eAAO,MAAM,YAAY,GAAU,eAAe,MAAM,EAAE,aAAa,OAAO,UAAU,kBA6BvF,CAAA"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}