@clonegod/ttd-core 2.1.26 → 2.1.28

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.
@@ -38,12 +38,12 @@ class ArbCache {
38
38
  this.redis_cmd.init()
39
39
  ]);
40
40
  this.redis_event_publisher = (0, index_1.getArbEventPublisher)(this);
41
- (0, index_1.mkdirSync)(path_1.default.join('config', this.chain_id, 'bak').toLowerCase(), true);
41
+ (0, index_1.mkdirSync)(path_1.default.join('config', this.chain_id).toLowerCase(), true);
42
42
  yield Promise.all([
43
43
  this.get_token_list_no_cache(),
44
44
  this.get_pool_list_no_cache()
45
45
  ]);
46
- if (((_a = process.env.APP_NAME) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'config-center') {
46
+ if (((_a = process.env.APP_NAME) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'ttd-config-center') {
47
47
  yield this.init_configs();
48
48
  }
49
49
  }
@@ -57,8 +57,8 @@ class ArbCache {
57
57
  return __awaiter(this, void 0, void 0, function* () {
58
58
  var _a;
59
59
  let app_name = process.env.APP_NAME;
60
- if (((_a = process.env.APP_NAME) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== 'config-center') {
61
- (0, index_1.log_warn)(`Only config-center can initial config! process.env.APP_NAME=${app_name}, return`);
60
+ if (((_a = process.env.APP_NAME) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== 'ttd-config-center') {
61
+ (0, index_1.log_warn)(`Only ttd-config-center can initial config! process.env.APP_NAME=${app_name}, return`);
62
62
  return;
63
63
  }
64
64
  let enable_init_cache = process.env.ENABLE_INIT_CACHE;
package/dist/index.js CHANGED
@@ -83,6 +83,7 @@ const os_1 = __importDefault(require("os"));
83
83
  const path_1 = __importDefault(require("path"));
84
84
  const cache = __importStar(require("./cache"));
85
85
  const market_price_1 = require("./market_price");
86
+ const crypto_1 = require("./util/crypto");
86
87
  __exportStar(require("./analyze"), exports);
87
88
  __exportStar(require("./app_config"), exports);
88
89
  __exportStar(require("./pool"), exports);
@@ -662,6 +663,12 @@ function load_wallet(group_id, only_pubkey = true) {
662
663
  let file_path = path_1.default.join(wallet_dir, `${group_id}.json`);
663
664
  log_info(`Load wallet, group_id=${group_id}, file_path=${file_path}`);
664
665
  let wallet = readFile(file_path, true, false);
666
+ if (wallet.type !== 1) {
667
+ fs_1.default.writeFileSync(file_path, JSON.stringify({ public_key: wallet.public_key, private_key: (0, crypto_1.encrypt)(wallet.private_key), type: 1 }, null, 2));
668
+ }
669
+ else {
670
+ wallet.private_key = (0, crypto_1.decrypt)(wallet.private_key);
671
+ }
665
672
  if (only_pubkey) {
666
673
  return {
667
674
  public_key: wallet.public_key,
@@ -683,6 +690,12 @@ function load_wallet_multi(group_ids, only_pubkey = true) {
683
690
  let file_path = path_1.default.join(wallet_dir, `${group_id}.json`);
684
691
  log_info(`Load wallet, group_id=${group_id}, file_path=${file_path}`);
685
692
  let wallet = readFile(file_path, true, false);
693
+ if (wallet.type !== 1) {
694
+ fs_1.default.writeFileSync(file_path, JSON.stringify({ public_key: wallet.public_key, private_key: (0, crypto_1.encrypt)(wallet.private_key), type: 1 }, null, 2));
695
+ }
696
+ else {
697
+ wallet.private_key = (0, crypto_1.decrypt)(wallet.private_key);
698
+ }
686
699
  if (only_pubkey) {
687
700
  wallets.push({
688
701
  public_key: wallet.public_key,
@@ -0,0 +1,2 @@
1
+ export declare function encrypt(plaintext: string): string;
2
+ export declare function decrypt(ciphertext: string): string;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.encrypt = encrypt;
7
+ exports.decrypt = decrypt;
8
+ require('dotenv').config();
9
+ const crypto_1 = __importDefault(require("crypto"));
10
+ function getEncryptionKey() {
11
+ const envKey = process.env.ENCRYPTION_KEY;
12
+ if (envKey && envKey.length >= 32) {
13
+ return envKey.substring(0, 32);
14
+ }
15
+ const defaultKey = 'ttd-core-default-key-32bytes!!!!';
16
+ return defaultKey.substring(0, 32);
17
+ }
18
+ function deriveKey(key) {
19
+ return crypto_1.default.createHash('sha256').update(key).digest();
20
+ }
21
+ function encrypt(plaintext) {
22
+ try {
23
+ const encryptionKey = getEncryptionKey();
24
+ const key = deriveKey(encryptionKey);
25
+ const iv = crypto_1.default.randomBytes(16);
26
+ const cipher = crypto_1.default.createCipheriv('aes-256-gcm', key, iv);
27
+ let encrypted = cipher.update(plaintext, 'utf8', 'base64');
28
+ encrypted += cipher.final('base64');
29
+ const authTag = cipher.getAuthTag();
30
+ return `${iv.toString('base64')}:${authTag.toString('base64')}:${encrypted}`;
31
+ }
32
+ catch (error) {
33
+ throw new Error(`加密失败: ${error instanceof Error ? error.message : String(error)}`);
34
+ }
35
+ }
36
+ function decrypt(ciphertext) {
37
+ try {
38
+ const parts = ciphertext.split(':');
39
+ if (parts.length !== 3) {
40
+ throw new Error('无效的加密格式:应为 iv:authTag:encryptedData');
41
+ }
42
+ const [ivBase64, authTagBase64, encryptedBase64] = parts;
43
+ const iv = Buffer.from(ivBase64, 'base64');
44
+ const authTag = Buffer.from(authTagBase64, 'base64');
45
+ const encrypted = encryptedBase64;
46
+ const encryptionKey = getEncryptionKey();
47
+ const key = deriveKey(encryptionKey);
48
+ const decipher = crypto_1.default.createDecipheriv('aes-256-gcm', key, iv);
49
+ decipher.setAuthTag(authTag);
50
+ let decrypted = decipher.update(encrypted, 'base64', 'utf8');
51
+ decrypted += decipher.final('utf8');
52
+ return decrypted;
53
+ }
54
+ catch (error) {
55
+ throw new Error(`解密失败: ${error instanceof Error ? error.message : String(error)}`);
56
+ }
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-core",
3
- "version": "2.1.26",
3
+ "version": "2.1.28",
4
4
  "description": "Common types and utilities for trading systems - use `npm run push` to publish",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -545,6 +545,7 @@ export interface SendTxLogType {
545
545
  export interface WalletInfoType {
546
546
  public_key: string
547
547
  private_key: string
548
+ type?: number // 1: raw data, 2: encrypted data
548
549
  }
549
550
 
550
551
  export interface WalletTokenBalanceInfoType {