@agirails/sdk 2.5.3 → 2.5.4

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 (166) hide show
  1. package/dist/ACTPClient.d.ts +18 -0
  2. package/dist/ACTPClient.d.ts.map +1 -1
  3. package/dist/ACTPClient.js +67 -22
  4. package/dist/ACTPClient.js.map +1 -1
  5. package/dist/adapters/BasicAdapter.d.ts +12 -0
  6. package/dist/adapters/BasicAdapter.d.ts.map +1 -1
  7. package/dist/adapters/BasicAdapter.js +30 -4
  8. package/dist/adapters/BasicAdapter.js.map +1 -1
  9. package/dist/adapters/StandardAdapter.d.ts +20 -3
  10. package/dist/adapters/StandardAdapter.d.ts.map +1 -1
  11. package/dist/adapters/StandardAdapter.js +45 -11
  12. package/dist/adapters/StandardAdapter.js.map +1 -1
  13. package/dist/cli/commands/publish.js +16 -4
  14. package/dist/cli/commands/publish.js.map +1 -1
  15. package/dist/cli/commands/register.js +16 -4
  16. package/dist/cli/commands/register.js.map +1 -1
  17. package/dist/cli/commands/tx.js +31 -3
  18. package/dist/cli/commands/tx.js.map +1 -1
  19. package/dist/config/networks.d.ts +2 -2
  20. package/dist/config/networks.d.ts.map +1 -1
  21. package/dist/config/networks.js +27 -22
  22. package/dist/config/networks.js.map +1 -1
  23. package/dist/level0/request.d.ts.map +1 -1
  24. package/dist/level0/request.js +2 -1
  25. package/dist/level0/request.js.map +1 -1
  26. package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
  27. package/dist/runtime/BlockchainRuntime.js +11 -5
  28. package/dist/runtime/BlockchainRuntime.js.map +1 -1
  29. package/dist/utils/IPFSClient.d.ts +3 -1
  30. package/dist/utils/IPFSClient.d.ts.map +1 -1
  31. package/dist/utils/IPFSClient.js +27 -7
  32. package/dist/utils/IPFSClient.js.map +1 -1
  33. package/dist/wallet/AutoWalletProvider.d.ts.map +1 -1
  34. package/dist/wallet/AutoWalletProvider.js +52 -18
  35. package/dist/wallet/AutoWalletProvider.js.map +1 -1
  36. package/dist/wallet/SmartWalletRouter.d.ts +116 -0
  37. package/dist/wallet/SmartWalletRouter.d.ts.map +1 -0
  38. package/dist/wallet/SmartWalletRouter.js +212 -0
  39. package/dist/wallet/SmartWalletRouter.js.map +1 -0
  40. package/dist/wallet/aa/DualNonceManager.d.ts +19 -0
  41. package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -1
  42. package/dist/wallet/aa/DualNonceManager.js +100 -5
  43. package/dist/wallet/aa/DualNonceManager.js.map +1 -1
  44. package/package.json +3 -6
  45. package/src/ACTPClient.ts +0 -1579
  46. package/src/abi/ACTPKernel.json +0 -1356
  47. package/src/abi/AgentRegistry.json +0 -915
  48. package/src/abi/ERC20.json +0 -40
  49. package/src/abi/EscrowVault.json +0 -134
  50. package/src/abi/IdentityRegistry.json +0 -316
  51. package/src/adapters/AdapterRegistry.ts +0 -173
  52. package/src/adapters/AdapterRouter.ts +0 -416
  53. package/src/adapters/BaseAdapter.ts +0 -498
  54. package/src/adapters/BasicAdapter.ts +0 -514
  55. package/src/adapters/IAdapter.ts +0 -292
  56. package/src/adapters/StandardAdapter.ts +0 -555
  57. package/src/adapters/X402Adapter.ts +0 -731
  58. package/src/adapters/index.ts +0 -60
  59. package/src/builders/DeliveryProofBuilder.ts +0 -327
  60. package/src/builders/QuoteBuilder.ts +0 -483
  61. package/src/builders/index.ts +0 -17
  62. package/src/cli/commands/balance.ts +0 -110
  63. package/src/cli/commands/batch.ts +0 -487
  64. package/src/cli/commands/config.ts +0 -231
  65. package/src/cli/commands/deploy-check.ts +0 -364
  66. package/src/cli/commands/deploy-env.ts +0 -120
  67. package/src/cli/commands/diff.ts +0 -141
  68. package/src/cli/commands/init.ts +0 -469
  69. package/src/cli/commands/mint.ts +0 -116
  70. package/src/cli/commands/pay.ts +0 -113
  71. package/src/cli/commands/publish.ts +0 -475
  72. package/src/cli/commands/pull.ts +0 -124
  73. package/src/cli/commands/register.ts +0 -247
  74. package/src/cli/commands/simulate.ts +0 -345
  75. package/src/cli/commands/time.ts +0 -302
  76. package/src/cli/commands/tx.ts +0 -448
  77. package/src/cli/commands/watch.ts +0 -211
  78. package/src/cli/index.ts +0 -134
  79. package/src/cli/utils/client.ts +0 -252
  80. package/src/cli/utils/config.ts +0 -389
  81. package/src/cli/utils/output.ts +0 -465
  82. package/src/cli/utils/wallet.ts +0 -109
  83. package/src/config/agirailsmd.ts +0 -262
  84. package/src/config/networks.ts +0 -275
  85. package/src/config/pendingPublish.ts +0 -237
  86. package/src/config/publishPipeline.ts +0 -359
  87. package/src/config/syncOperations.ts +0 -279
  88. package/src/erc8004/ERC8004Bridge.ts +0 -462
  89. package/src/erc8004/ReputationReporter.ts +0 -468
  90. package/src/erc8004/index.ts +0 -61
  91. package/src/errors/index.ts +0 -427
  92. package/src/index.ts +0 -364
  93. package/src/level0/Provider.ts +0 -117
  94. package/src/level0/ServiceDirectory.ts +0 -131
  95. package/src/level0/index.ts +0 -10
  96. package/src/level0/provide.ts +0 -132
  97. package/src/level0/request.ts +0 -432
  98. package/src/level1/Agent.ts +0 -1426
  99. package/src/level1/index.ts +0 -10
  100. package/src/level1/pricing/PriceCalculator.ts +0 -255
  101. package/src/level1/pricing/PricingStrategy.ts +0 -198
  102. package/src/level1/types/Job.ts +0 -179
  103. package/src/level1/types/Options.ts +0 -291
  104. package/src/level1/types/index.ts +0 -8
  105. package/src/protocol/ACTPKernel.ts +0 -808
  106. package/src/protocol/AgentRegistry.ts +0 -559
  107. package/src/protocol/DIDManager.ts +0 -629
  108. package/src/protocol/DIDResolver.ts +0 -554
  109. package/src/protocol/EASHelper.ts +0 -378
  110. package/src/protocol/EscrowVault.ts +0 -255
  111. package/src/protocol/EventMonitor.ts +0 -204
  112. package/src/protocol/MessageSigner.ts +0 -510
  113. package/src/protocol/ProofGenerator.ts +0 -339
  114. package/src/protocol/QuoteBuilder.ts +0 -15
  115. package/src/registry/AgentRegistryClient.ts +0 -202
  116. package/src/runtime/BlockchainRuntime.ts +0 -1015
  117. package/src/runtime/IACTPRuntime.ts +0 -306
  118. package/src/runtime/MockRuntime.ts +0 -1298
  119. package/src/runtime/MockStateManager.ts +0 -577
  120. package/src/runtime/index.ts +0 -25
  121. package/src/runtime/types/MockState.ts +0 -237
  122. package/src/storage/ArchiveBundleBuilder.ts +0 -561
  123. package/src/storage/ArweaveClient.ts +0 -946
  124. package/src/storage/FilebaseClient.ts +0 -790
  125. package/src/storage/index.ts +0 -96
  126. package/src/storage/types.ts +0 -348
  127. package/src/types/adapter.ts +0 -310
  128. package/src/types/agent.ts +0 -79
  129. package/src/types/did.ts +0 -223
  130. package/src/types/eip712.ts +0 -175
  131. package/src/types/erc8004.ts +0 -293
  132. package/src/types/escrow.ts +0 -27
  133. package/src/types/index.ts +0 -17
  134. package/src/types/message.ts +0 -145
  135. package/src/types/state.ts +0 -87
  136. package/src/types/transaction.ts +0 -69
  137. package/src/types/x402.ts +0 -251
  138. package/src/utils/ErrorRecoveryGuide.ts +0 -676
  139. package/src/utils/Helpers.ts +0 -688
  140. package/src/utils/IPFSClient.ts +0 -368
  141. package/src/utils/Logger.ts +0 -484
  142. package/src/utils/NonceManager.ts +0 -591
  143. package/src/utils/RateLimiter.ts +0 -534
  144. package/src/utils/ReceivedNonceTracker.ts +0 -567
  145. package/src/utils/SDKLifecycle.ts +0 -416
  146. package/src/utils/SecureNonce.ts +0 -78
  147. package/src/utils/Semaphore.ts +0 -276
  148. package/src/utils/UsedAttestationTracker.ts +0 -385
  149. package/src/utils/canonicalJson.ts +0 -38
  150. package/src/utils/circuitBreaker.ts +0 -324
  151. package/src/utils/computeTypeHash.ts +0 -48
  152. package/src/utils/fsSafe.ts +0 -80
  153. package/src/utils/index.ts +0 -80
  154. package/src/utils/retry.ts +0 -364
  155. package/src/utils/security.ts +0 -418
  156. package/src/utils/validation.ts +0 -540
  157. package/src/wallet/AutoWalletProvider.ts +0 -299
  158. package/src/wallet/EOAWalletProvider.ts +0 -69
  159. package/src/wallet/IWalletProvider.ts +0 -135
  160. package/src/wallet/aa/BundlerClient.ts +0 -274
  161. package/src/wallet/aa/DualNonceManager.ts +0 -173
  162. package/src/wallet/aa/PaymasterClient.ts +0 -174
  163. package/src/wallet/aa/TransactionBatcher.ts +0 -353
  164. package/src/wallet/aa/UserOpBuilder.ts +0 -246
  165. package/src/wallet/aa/constants.ts +0 -60
  166. package/src/wallet/keystore.ts +0 -240
@@ -1,487 +0,0 @@
1
- /**
2
- * Batch Command - Execute multiple commands from a file
3
- *
4
- * Agent-first feature: Process commands in bulk.
5
- * Perfect for:
6
- * - Scripted workflows
7
- * - Replaying transaction sequences
8
- * - Automated testing
9
- *
10
- * Security: Commands are validated against an allowlist and arguments
11
- * are passed as an array to avoid shell injection attacks.
12
- *
13
- * @module cli/commands/batch
14
- */
15
-
16
- import * as fs from 'fs';
17
- import * as readline from 'readline';
18
- import { Command } from 'commander';
19
- import { Output, ExitCode, fmt } from '../utils/output';
20
- import { mapError } from '../utils/client';
21
-
22
- // ============================================================================
23
- // Security: Command Allowlist and Argument Parsing
24
- // ============================================================================
25
-
26
- /**
27
- * Allowlist of valid ACTP subcommands.
28
- * Only these commands can be executed through batch mode.
29
- * This prevents command injection attacks.
30
- */
31
- const VALID_SUBCOMMANDS = new Set([
32
- 'init', 'pay', 'tx', 'balance', 'mint', 'config',
33
- 'watch', 'simulate', 'time',
34
- ]);
35
-
36
- /**
37
- * Allowlist of valid 'tx' subcommands.
38
- */
39
- const VALID_TX_SUBCOMMANDS = new Set([
40
- 'create', 'status', 'list', 'deliver', 'settle', 'cancel',
41
- ]);
42
-
43
- /**
44
- * Characters that are not allowed in command arguments.
45
- * These could be used for shell injection attacks.
46
- */
47
- const DANGEROUS_CHARS_PATTERN = /[;&|`$(){}[\]<>!\\'"]/;
48
-
49
- /**
50
- * Parse a command string into an array of arguments safely.
51
- * Does NOT use shell for parsing - handles quotes manually.
52
- *
53
- * @param command - Raw command string
54
- * @returns Array of parsed arguments
55
- * @throws Error if command contains dangerous characters
56
- */
57
- function parseCommandArgs(command: string): string[] {
58
- const args: string[] = [];
59
- let current = '';
60
- let inQuotes = false;
61
- let quoteChar = '';
62
-
63
- // Check for dangerous characters outside quotes
64
- const cleanCommand = command.replace(/"[^"]*"|'[^']*'/g, ''); // Remove quoted strings
65
- if (DANGEROUS_CHARS_PATTERN.test(cleanCommand)) {
66
- throw new Error(
67
- 'Command contains potentially dangerous characters. ' +
68
- 'Shell metacharacters are not allowed for security reasons.'
69
- );
70
- }
71
-
72
- for (let i = 0; i < command.length; i++) {
73
- const char = command[i];
74
-
75
- if (inQuotes) {
76
- if (char === quoteChar) {
77
- inQuotes = false;
78
- quoteChar = '';
79
- } else {
80
- current += char;
81
- }
82
- } else if (char === '"' || char === "'") {
83
- inQuotes = true;
84
- quoteChar = char;
85
- } else if (char === ' ' || char === '\t') {
86
- if (current) {
87
- args.push(current);
88
- current = '';
89
- }
90
- } else {
91
- current += char;
92
- }
93
- }
94
-
95
- if (current) {
96
- args.push(current);
97
- }
98
-
99
- if (inQuotes) {
100
- throw new Error('Unclosed quote in command');
101
- }
102
-
103
- return args;
104
- }
105
-
106
- /**
107
- * Validate that a command only uses allowed subcommands.
108
- *
109
- * @param args - Parsed command arguments
110
- * @returns true if command is valid
111
- * @throws Error if command is not in allowlist
112
- */
113
- function validateCommand(args: string[]): boolean {
114
- if (args.length === 0) {
115
- throw new Error('Empty command');
116
- }
117
-
118
- const subcommand = args[0];
119
-
120
- if (subcommand === 'tx') {
121
- if (args.length < 2) {
122
- throw new Error('tx command requires a subcommand');
123
- }
124
- if (!VALID_TX_SUBCOMMANDS.has(args[1])) {
125
- throw new Error(`Unknown tx subcommand: ${args[1]}. Allowed: ${Array.from(VALID_TX_SUBCOMMANDS).join(', ')}`);
126
- }
127
- return true;
128
- }
129
-
130
- if (!VALID_SUBCOMMANDS.has(subcommand)) {
131
- throw new Error(`Unknown command: ${subcommand}. Allowed: ${Array.from(VALID_SUBCOMMANDS).join(', ')}`);
132
- }
133
-
134
- return true;
135
- }
136
-
137
- // ============================================================================
138
- // Command Definition
139
- // ============================================================================
140
-
141
- export function createBatchCommand(): Command {
142
- const cmd = new Command('batch')
143
- .description('Execute multiple commands from a file (agent-first feature)')
144
- .argument('[file]', 'File containing commands (one per line), or - for stdin')
145
- .option('--dry-run', 'Parse and validate commands without executing')
146
- .option('--stop-on-error', 'Stop execution on first error', false)
147
- .option('--json', 'Output as JSON')
148
- .option('-q, --quiet', 'Minimal output')
149
- .action(async (file, options) => {
150
- const output = new Output(
151
- options.json ? 'json' : options.quiet ? 'quiet' : 'human'
152
- );
153
-
154
- try {
155
- await runBatch(file, options, output);
156
- } catch (error) {
157
- const structuredError = mapError(error);
158
- output.errorResult({
159
- code: structuredError.code,
160
- message: structuredError.message,
161
- });
162
- process.exit(ExitCode.ERROR);
163
- }
164
- });
165
-
166
- return cmd;
167
- }
168
-
169
- // ============================================================================
170
- // Implementation
171
- // ============================================================================
172
-
173
- interface BatchOptions {
174
- dryRun?: boolean;
175
- stopOnError?: boolean;
176
- }
177
-
178
- interface BatchResult {
179
- line: number;
180
- command: string;
181
- status: 'success' | 'error' | 'skipped';
182
- output?: string;
183
- error?: string;
184
- duration?: number;
185
- }
186
-
187
- async function runBatch(
188
- file: string | undefined,
189
- options: BatchOptions,
190
- output: Output
191
- ): Promise<void> {
192
- // Read commands
193
- let commands: string[];
194
-
195
- if (!file || file === '-') {
196
- // Read from stdin
197
- commands = await readStdin();
198
- } else {
199
- // Read from file
200
- if (!fs.existsSync(file)) {
201
- throw new Error(`File not found: ${file}`);
202
- }
203
- commands = fs.readFileSync(file, 'utf-8').split('\n');
204
- }
205
-
206
- // Filter empty lines and comments
207
- const commandsWithLine = commands
208
- .map((line, index) => ({ line: index + 1, command: line.trim() }))
209
- .filter(({ command }) => command && !command.startsWith('#'));
210
-
211
- if (commandsWithLine.length === 0) {
212
- output.warning('No commands to execute.');
213
- return;
214
- }
215
-
216
- output.info(`Processing ${commandsWithLine.length} command(s)...`);
217
- output.blank();
218
-
219
- const results: BatchResult[] = [];
220
- let successCount = 0;
221
- let errorCount = 0;
222
- let skippedCount = 0;
223
-
224
- for (const { line, command } of commandsWithLine) {
225
- const startTime = Date.now();
226
-
227
- if (options.dryRun) {
228
- // Dry run: just parse and validate
229
- const parseResult = parseCommand(command);
230
-
231
- if (parseResult.valid) {
232
- results.push({
233
- line,
234
- command,
235
- status: 'success',
236
- output: `Would execute: ${parseResult.parsed}`,
237
- });
238
- successCount++;
239
- outputDryRunResult(output, line, command, true, parseResult.parsed);
240
- } else {
241
- results.push({
242
- line,
243
- command,
244
- status: 'error',
245
- error: parseResult.error,
246
- });
247
- errorCount++;
248
- outputDryRunResult(output, line, command, false, parseResult.error);
249
-
250
- if (options.stopOnError) {
251
- output.error('Stopping on error (--stop-on-error)');
252
- break;
253
- }
254
- }
255
- } else {
256
- // Execute command
257
- try {
258
- const result = await executeCommand(command);
259
- const duration = Date.now() - startTime;
260
-
261
- results.push({
262
- line,
263
- command,
264
- status: 'success',
265
- output: result,
266
- duration,
267
- });
268
- successCount++;
269
- outputExecutionResult(output, line, command, true, result, duration);
270
- } catch (error) {
271
- const duration = Date.now() - startTime;
272
- const errorMessage = (error as Error).message;
273
-
274
- results.push({
275
- line,
276
- command,
277
- status: 'error',
278
- error: errorMessage,
279
- duration,
280
- });
281
- errorCount++;
282
- outputExecutionResult(output, line, command, false, errorMessage, duration);
283
-
284
- if (options.stopOnError) {
285
- output.error('Stopping on error (--stop-on-error)');
286
- skippedCount = commandsWithLine.length - successCount - errorCount;
287
- break;
288
- }
289
- }
290
- }
291
- }
292
-
293
- // Summary
294
- output.blank();
295
- output.section('Batch Summary');
296
- output.keyValue('Total Commands', commandsWithLine.length);
297
- output.keyValue('Succeeded', successCount);
298
- output.keyValue('Failed', errorCount);
299
- if (skippedCount > 0) {
300
- output.keyValue('Skipped', skippedCount);
301
- }
302
-
303
- // Exit with appropriate code
304
- if (errorCount > 0) {
305
- process.exit(ExitCode.ERROR);
306
- }
307
- }
308
-
309
- /**
310
- * Read commands from stdin
311
- */
312
- async function readStdin(): Promise<string[]> {
313
- return new Promise((resolve) => {
314
- const lines: string[] = [];
315
-
316
- const rl = readline.createInterface({
317
- input: process.stdin,
318
- output: process.stdout,
319
- terminal: false,
320
- });
321
-
322
- rl.on('line', (line) => {
323
- lines.push(line);
324
- });
325
-
326
- rl.on('close', () => {
327
- resolve(lines);
328
- });
329
- });
330
- }
331
-
332
- /**
333
- * Parse and validate a command (for dry-run)
334
- *
335
- * Security: Uses parseCommandArgs for safe argument parsing
336
- * and validates against allowlist.
337
- */
338
- function parseCommand(command: string): {
339
- valid: boolean;
340
- parsed?: string;
341
- args?: string[];
342
- error?: string;
343
- } {
344
- try {
345
- // Parse command safely (no shell interpretation)
346
- const args = parseCommandArgs(command);
347
-
348
- if (args.length === 0) {
349
- return { valid: false, error: 'Empty command' };
350
- }
351
-
352
- // Validate against allowlist
353
- validateCommand(args);
354
-
355
- return {
356
- valid: true,
357
- parsed: `actp ${args.join(' ')}`,
358
- args,
359
- };
360
- } catch (error) {
361
- return {
362
- valid: false,
363
- error: (error as Error).message,
364
- };
365
- }
366
- }
367
-
368
- /**
369
- * Execute a command (by spawning a child process)
370
- *
371
- * SECURITY FIX: No longer uses shell interpolation.
372
- * Arguments are passed as an array directly to the actp binary.
373
- * This prevents command injection attacks.
374
- */
375
- async function executeCommand(command: string): Promise<string> {
376
- const { spawn } = await import('child_process');
377
-
378
- return new Promise((resolve, reject) => {
379
- // Parse command safely - no shell interpretation
380
- let args: string[];
381
- try {
382
- args = parseCommandArgs(command);
383
- validateCommand(args);
384
- } catch (error) {
385
- reject(error);
386
- return;
387
- }
388
-
389
- // Add --json flag for structured output
390
- args.push('--json');
391
-
392
- // SECURITY: Use shell: false and pass arguments as array
393
- // This prevents any shell interpretation of the arguments
394
- const child = spawn('actp', args, {
395
- stdio: ['inherit', 'pipe', 'pipe'],
396
- env: { ...process.env },
397
- shell: false, // CRITICAL: Do not use shell
398
- });
399
-
400
- let stdout = '';
401
- let stderr = '';
402
-
403
- child.stdout.on('data', (data) => {
404
- stdout += data.toString();
405
- });
406
-
407
- child.stderr.on('data', (data) => {
408
- stderr += data.toString();
409
- });
410
-
411
- child.on('close', (code) => {
412
- if (code === 0) {
413
- resolve(stdout.trim() || 'OK');
414
- } else {
415
- // Try to parse error from JSON output
416
- try {
417
- const errorObj = JSON.parse(stderr || stdout);
418
- reject(new Error(errorObj.error?.message || 'Command failed'));
419
- } catch {
420
- reject(new Error(stderr.trim() || stdout.trim() || `Exit code: ${code}`));
421
- }
422
- }
423
- });
424
-
425
- child.on('error', (error) => {
426
- reject(error);
427
- });
428
- });
429
- }
430
-
431
- /**
432
- * Output dry-run result
433
- */
434
- function outputDryRunResult(
435
- output: Output,
436
- line: number,
437
- command: string,
438
- success: boolean,
439
- message?: string
440
- ): void {
441
- if (output['mode'] === 'json') {
442
- return; // JSON output is aggregated at the end
443
- }
444
-
445
- if (output['mode'] === 'quiet') {
446
- console.log(success ? 'OK' : 'ERROR');
447
- return;
448
- }
449
-
450
- const lineStr = `[${line}]`.padEnd(5);
451
- const status = success ? fmt.green('VALID') : fmt.red('INVALID');
452
- console.log(`${fmt.dim(lineStr)} ${status} ${fmt.dim(command)}`);
453
- if (message && !success) {
454
- console.log(` ${fmt.red(message)}`);
455
- }
456
- }
457
-
458
- /**
459
- * Output execution result
460
- */
461
- function outputExecutionResult(
462
- output: Output,
463
- line: number,
464
- command: string,
465
- success: boolean,
466
- message: string,
467
- durationMs: number
468
- ): void {
469
- if (output['mode'] === 'json') {
470
- return; // JSON output is aggregated at the end
471
- }
472
-
473
- if (output['mode'] === 'quiet') {
474
- console.log(success ? 'OK' : 'ERROR');
475
- return;
476
- }
477
-
478
- const lineStr = `[${line}]`.padEnd(5);
479
- const status = success ? fmt.green('OK') : fmt.red('FAIL');
480
- const duration = fmt.dim(`(${durationMs}ms)`);
481
- console.log(`${fmt.dim(lineStr)} ${status} ${command} ${duration}`);
482
- if (!success) {
483
- console.log(` ${fmt.red(message)}`);
484
- }
485
- }
486
-
487
- export { runBatch };
@@ -1,231 +0,0 @@
1
- /**
2
- * Config Command - View and modify CLI configuration
3
- *
4
- * Commands:
5
- * - config show: Display current configuration
6
- * - config set <key> <value>: Set a configuration value
7
- * - config get <key>: Get a specific configuration value
8
- *
9
- * @module cli/commands/config
10
- */
11
-
12
- import { Command } from 'commander';
13
- import { Output, ExitCode } from '../utils/output';
14
- import {
15
- loadConfig,
16
- updateConfig,
17
- CLIConfig,
18
- CLIMode,
19
- validateAddress,
20
- validatePrivateKey,
21
- } from '../utils/config';
22
- import { mapError } from '../utils/client';
23
-
24
- // ============================================================================
25
- // Main config Command
26
- // ============================================================================
27
-
28
- export function createConfigCommand(): Command {
29
- const cmd = new Command('config')
30
- .description('View and modify configuration');
31
-
32
- cmd.addCommand(createConfigShowCommand());
33
- cmd.addCommand(createConfigSetCommand());
34
- cmd.addCommand(createConfigGetCommand());
35
-
36
- return cmd;
37
- }
38
-
39
- // ============================================================================
40
- // config show
41
- // ============================================================================
42
-
43
- function createConfigShowCommand(): Command {
44
- return new Command('show')
45
- .description('Display current configuration')
46
- .option('--json', 'Output as JSON')
47
- .action(async (options) => {
48
- const output = new Output(options.json ? 'json' : 'human');
49
-
50
- try {
51
- const config = loadConfig();
52
-
53
- // SECURITY FIX (C-1): Mask private key - show only last 4 chars
54
- // Previous code showed 14 chars which reduces keyspace significantly
55
- const displayConfig = {
56
- ...config,
57
- privateKey: config.privateKey
58
- ? '****' + config.privateKey.slice(-4)
59
- : undefined,
60
- };
61
-
62
- if (options.json) {
63
- output.result(displayConfig);
64
- } else {
65
- output.section('ACTP Configuration');
66
- output.keyValue('Mode', config.mode);
67
- output.keyValue('Address', config.address);
68
- output.keyValue('Version', config.version);
69
- if (config.privateKey) {
70
- output.keyValue('Private Key', '****' + config.privateKey.slice(-4));
71
- }
72
- if (config.rpcUrl) {
73
- output.keyValue('RPC URL', config.rpcUrl);
74
- }
75
- }
76
- } catch (error) {
77
- const structuredError = mapError(error);
78
- output.errorResult({
79
- code: structuredError.code,
80
- message: structuredError.message,
81
- });
82
- process.exit(ExitCode.ERROR);
83
- }
84
- });
85
- }
86
-
87
- // ============================================================================
88
- // config set
89
- // ============================================================================
90
-
91
- function createConfigSetCommand(): Command {
92
- return new Command('set')
93
- .description('Set a configuration value')
94
- .argument('<key>', 'Configuration key (mode, address, privateKey, rpcUrl)')
95
- .argument('<value>', 'Value to set')
96
- .option('--json', 'Output as JSON')
97
- .action(async (key, value, options) => {
98
- const output = new Output(options.json ? 'json' : 'human');
99
-
100
- try {
101
- // Validate key
102
- const validKeys = ['mode', 'address', 'privateKey', 'rpcUrl'];
103
- if (!validKeys.includes(key)) {
104
- throw new Error(
105
- `Invalid config key: "${key}"\n` +
106
- `Valid keys: ${validKeys.join(', ')}`
107
- );
108
- }
109
-
110
- // Validate value based on key
111
- switch (key) {
112
- case 'mode': {
113
- const validModes: CLIMode[] = ['mock', 'testnet', 'mainnet'];
114
- if (!validModes.includes(value as CLIMode)) {
115
- throw new Error(
116
- `Invalid mode: "${value}"\n` +
117
- `Valid modes: ${validModes.join(', ')}`
118
- );
119
- }
120
- break;
121
- }
122
-
123
- case 'address':
124
- if (!validateAddress(value)) {
125
- throw new Error(
126
- `Invalid address: "${value}"\n` +
127
- 'Expected 0x-prefixed 40-character hex string.'
128
- );
129
- }
130
- break;
131
-
132
- case 'privateKey':
133
- if (!validatePrivateKey(value)) {
134
- throw new Error(
135
- `Invalid private key format.\n` +
136
- 'Expected 64-character hex string (with or without 0x prefix).'
137
- );
138
- }
139
- // Normalize: ensure no 0x prefix for storage
140
- value = value.startsWith('0x') ? value.slice(2) : value;
141
- break;
142
-
143
- case 'rpcUrl':
144
- if (!value.startsWith('http://') && !value.startsWith('https://')) {
145
- throw new Error(
146
- `Invalid RPC URL: "${value}"\n` +
147
- 'Expected URL starting with http:// or https://'
148
- );
149
- }
150
- break;
151
- }
152
-
153
- // Update config
154
- const updates: Partial<CLIConfig> = { [key]: value };
155
- if (key === 'address') {
156
- updates.address = value.toLowerCase();
157
- }
158
-
159
- updateConfig(updates);
160
-
161
- output.result({
162
- [key]: key === 'privateKey' ? '****' + value.slice(-4) : value,
163
- updated: true,
164
- });
165
-
166
- output.success(`Configuration updated: ${key}`);
167
- } catch (error) {
168
- const structuredError = mapError(error);
169
- output.errorResult({
170
- code: structuredError.code,
171
- message: structuredError.message,
172
- });
173
- process.exit(ExitCode.ERROR);
174
- }
175
- });
176
- }
177
-
178
- // ============================================================================
179
- // config get
180
- // ============================================================================
181
-
182
- function createConfigGetCommand(): Command {
183
- return new Command('get')
184
- .description('Get a specific configuration value')
185
- .argument('<key>', 'Configuration key')
186
- .option('--json', 'Output as JSON')
187
- .option('-q, --quiet', 'Output only the value')
188
- .action(async (key, options) => {
189
- const output = new Output(
190
- options.json ? 'json' : options.quiet ? 'quiet' : 'human'
191
- );
192
-
193
- try {
194
- const config = loadConfig();
195
-
196
- const validKeys = ['mode', 'address', 'privateKey', 'rpcUrl', 'version'];
197
- if (!validKeys.includes(key)) {
198
- throw new Error(
199
- `Invalid config key: "${key}"\n` +
200
- `Valid keys: ${validKeys.join(', ')}`
201
- );
202
- }
203
-
204
- const value = config[key as keyof CLIConfig];
205
-
206
- // Mask private key
207
- let displayValue = value;
208
- if (key === 'privateKey' && value) {
209
- displayValue = '****' + (value as string).slice(-4);
210
- }
211
-
212
- if (options.quiet) {
213
- if (value !== undefined) {
214
- console.log(key === 'privateKey' ? displayValue : value);
215
- }
216
- } else {
217
- output.result({
218
- key,
219
- value: displayValue ?? null,
220
- });
221
- }
222
- } catch (error) {
223
- const structuredError = mapError(error);
224
- output.errorResult({
225
- code: structuredError.code,
226
- message: structuredError.message,
227
- });
228
- process.exit(ExitCode.ERROR);
229
- }
230
- });
231
- }