decharge-scout 2.0.0 → 2.2.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/index.js CHANGED
@@ -20,13 +20,11 @@ import { Command } from 'commander';
20
20
  import chalk from 'chalk';
21
21
  import ora from 'ora';
22
22
  import dotenv from 'dotenv';
23
- import { readFileSync, writeFileSync, existsSync, readdirSync } from 'fs';
23
+ import { readFileSync, writeFileSync, existsSync } from 'fs';
24
24
  import { createInterface } from 'readline';
25
25
  import path from 'path';
26
26
  import { fileURLToPath } from 'url';
27
27
  import { dirname } from 'path';
28
- import { Keypair } from '@solana/web3.js';
29
- import os from 'os';
30
28
 
31
29
  // Load environment variables
32
30
  dotenv.config();
@@ -47,8 +45,6 @@ const __dirname = dirname(__filename);
47
45
  // Configuration
48
46
  const STAKE_AMOUNT = parseFloat(process.env.STAKE_AMOUNT || '0.01');
49
47
  const CYCLE_INTERVAL_MS = 15 * 60 * 1000; // 15 minutes
50
- // Use current working directory for wallet by default (not package installation dir)
51
- const DEFAULT_WALLET_PATH = path.join(process.cwd(), 'wallet.json');
52
48
 
53
49
  // Global state
54
50
  let isRunning = true;
@@ -71,166 +67,6 @@ function generateAgentName() {
71
67
  return `Agent-${randomId}`;
72
68
  }
73
69
 
74
- /**
75
- * Search for existing Solana wallets in common locations
76
- */
77
- function findExistingWallets() {
78
- const wallets = [];
79
- const homeDir = os.homedir();
80
- const cwd = process.cwd();
81
-
82
- const searchPaths = [
83
- // Current directory - most common
84
- path.join(cwd, 'wallet.json'),
85
- path.join(cwd, 'id.json'),
86
- path.join(cwd, 'keypair.json'),
87
- path.join(cwd, 'solana-wallet.json'),
88
- path.join(cwd, 'my-wallet.json'),
89
-
90
- // Package directory (for global installations)
91
- path.join(__dirname, 'wallet.json'),
92
- path.join(__dirname, 'id.json'),
93
-
94
- // Solana CLI default locations
95
- path.join(homeDir, '.config', 'solana', 'id.json'),
96
- path.join(homeDir, '.solana', 'id.json'),
97
- path.join(homeDir, '.solana', 'devnet.json'),
98
- path.join(homeDir, '.solana', 'testnet.json'),
99
-
100
- // Home directory
101
- path.join(homeDir, 'wallet.json'),
102
- path.join(homeDir, 'solana-wallet.json'),
103
-
104
- // Downloads (users often save here)
105
- path.join(homeDir, 'Downloads', 'wallet.json'),
106
- path.join(homeDir, 'Downloads', 'solana-wallet.json'),
107
- path.join(homeDir, 'Downloads', 'keypair.json'),
108
- ];
109
-
110
- for (const walletPath of searchPaths) {
111
- if (existsSync(walletPath)) {
112
- try {
113
- const keyData = JSON.parse(readFileSync(walletPath, 'utf-8'));
114
- if (Array.isArray(keyData) && keyData.length === 64) {
115
- const keypair = Keypair.fromSecretKey(Uint8Array.from(keyData));
116
- wallets.push({
117
- path: walletPath,
118
- publicKey: keypair.publicKey.toBase58(),
119
- name: path.basename(walletPath),
120
- location: path.dirname(walletPath)
121
- });
122
- }
123
- } catch (error) {
124
- // Skip invalid wallets
125
- }
126
- }
127
- }
128
-
129
- return wallets;
130
- }
131
-
132
- /**
133
- * Auto-create wallet if missing
134
- */
135
- async function ensureWallet(walletPath) {
136
- if (existsSync(walletPath)) {
137
- console.log(chalk.green(`✓ Using wallet: ${walletPath}`));
138
- return walletPath;
139
- }
140
-
141
- console.log(chalk.yellow(`\n⚠️ No wallet found at ${walletPath}`));
142
-
143
- // Search for existing wallets
144
- console.log(chalk.blue('🔍 Searching for existing Solana wallets...'));
145
- const existingWallets = findExistingWallets();
146
-
147
- if (existingWallets.length > 0) {
148
- console.log(chalk.green(`\n✓ Found ${existingWallets.length} existing wallet(s):\n`));
149
-
150
- existingWallets.forEach((wallet, index) => {
151
- console.log(chalk.cyan(` ${index + 1}. ${wallet.name}`));
152
- console.log(chalk.gray(` Path: ${wallet.path}`));
153
- console.log(chalk.gray(` Public Key: ${wallet.publicKey}\n`));
154
- });
155
-
156
- const useExisting = await question('Use an existing wallet? (Enter number, or press Enter to create new): ');
157
-
158
- if (useExisting.trim() && !isNaN(useExisting)) {
159
- const index = parseInt(useExisting.trim()) - 1;
160
- if (index >= 0 && index < existingWallets.length) {
161
- const selectedWallet = existingWallets[index];
162
- console.log(chalk.green(`✓ Using wallet: ${selectedWallet.publicKey}`));
163
- return selectedWallet.path;
164
- } else {
165
- console.log(chalk.yellow('Invalid selection, creating new wallet...'));
166
- }
167
- }
168
- } else {
169
- console.log(chalk.yellow('⚠️ No existing wallets found in common locations.'));
170
- console.log(chalk.gray(' Searched: ~/.solana/id.json, ./wallet.json, ./id.json, etc.\n'));
171
- }
172
-
173
- const answer = await question('Create a new wallet? (Y/n): ');
174
-
175
- if (answer.toLowerCase() === 'n') {
176
- console.log(chalk.blue('\n📥 Import existing wallet'));
177
- const importAnswer = await question('Do you want to import an existing wallet private key? (Y/n): ');
178
-
179
- if (importAnswer.toLowerCase() === 'n') {
180
- console.log(chalk.blue('\nYou can create a wallet manually:'));
181
- console.log(chalk.gray(' solana-keygen new --outfile ./wallet.json'));
182
- console.log(chalk.gray(' Or run: node setup.js\n'));
183
- process.exit(1);
184
- }
185
-
186
- console.log(chalk.yellow('\n⚠️ Enter your Solana wallet private key'));
187
- console.log(chalk.gray('Format: [1,2,3,...] (array of 64 numbers)'));
188
- const privateKeyInput = await question('Private key: ');
189
-
190
- try {
191
- // Parse the private key
192
- const privateKey = JSON.parse(privateKeyInput.trim());
193
-
194
- // Validate it's an array of numbers
195
- if (!Array.isArray(privateKey) || privateKey.length !== 64) {
196
- throw new Error('Invalid private key format');
197
- }
198
-
199
- // Create keypair to validate
200
- const keypair = Keypair.fromSecretKey(Uint8Array.from(privateKey));
201
-
202
- // Save to file
203
- writeFileSync(walletPath, JSON.stringify(privateKey));
204
-
205
- console.log(chalk.green(`✓ Wallet imported: ${keypair.publicKey.toBase58()}`));
206
- console.log(chalk.blue(`📁 Wallet saved to: ${walletPath}`));
207
- return walletPath;
208
- } catch (error) {
209
- console.log(chalk.red(`\n❌ Invalid private key: ${error.message}`));
210
- console.log(chalk.gray('Expected format: [1,2,3,...] (array of 64 numbers)\n'));
211
- process.exit(1);
212
- }
213
- }
214
-
215
- console.log(chalk.blue('Generating new wallet...'));
216
-
217
- const keypair = Keypair.generate();
218
- const secretKey = Array.from(keypair.secretKey);
219
-
220
- writeFileSync(walletPath, JSON.stringify(secretKey));
221
-
222
- console.log(chalk.green(`✓ Wallet created: ${keypair.publicKey.toBase58()}`));
223
- console.log(chalk.blue(`📁 Wallet saved to: ${walletPath}`));
224
- console.log(chalk.yellow('⚠️ IMPORTANT: Backup this wallet file!'));
225
- console.log(chalk.blue(`\nYou need devnet SOL. Get it from:`));
226
- console.log(chalk.gray(' solana airdrop 1 ' + keypair.publicKey.toBase58() + ' --url devnet'));
227
- console.log(chalk.gray(' Or visit: https://faucet.solana.com/\n'));
228
-
229
- await question('Press Enter after funding your wallet...');
230
-
231
- return walletPath;
232
- }
233
-
234
70
  /**
235
71
  * Auto-configure .env if needed
236
72
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "decharge-scout",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "AI-powered energy grid data scout with Solana integration",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -6,13 +6,15 @@
6
6
  */
7
7
 
8
8
  import express from 'express';
9
- import { WebSocketServer } from 'ws';
9
+ import WebSocket from 'ws';
10
10
  import path from 'path';
11
11
  import { fileURLToPath } from 'url';
12
12
  import { dirname } from 'path';
13
13
  import open from 'open';
14
14
  import chalk from 'chalk';
15
15
 
16
+ const { WebSocketServer } = WebSocket;
17
+
16
18
  const __filename = fileURLToPath(import.meta.url);
17
19
  const __dirname = dirname(__filename);
18
20