neozip-cli 0.70.0-alpha

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 (43) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/DOCUMENTATION.md +194 -0
  3. package/LICENSE +22 -0
  4. package/README.md +504 -0
  5. package/WHY_NEOZIP.md +212 -0
  6. package/bin/neolist +16 -0
  7. package/bin/neounzip +16 -0
  8. package/bin/neozip +15 -0
  9. package/dist/neozipkit-bundles/blockchain.js +13091 -0
  10. package/dist/neozipkit-bundles/browser.js +5733 -0
  11. package/dist/neozipkit-bundles/core.js +3766 -0
  12. package/dist/neozipkit-bundles/server.js +14996 -0
  13. package/dist/neozipkit-wrappers/blockchain/core/contracts.js +16 -0
  14. package/dist/neozipkit-wrappers/blockchain/index.js +2 -0
  15. package/dist/neozipkit-wrappers/core/ZipDecompress.js +2 -0
  16. package/dist/neozipkit-wrappers/core/components/HashCalculator.js +2 -0
  17. package/dist/neozipkit-wrappers/core/components/Logger.js +2 -0
  18. package/dist/neozipkit-wrappers/core/constants/Errors.js +2 -0
  19. package/dist/neozipkit-wrappers/core/constants/Headers.js +2 -0
  20. package/dist/neozipkit-wrappers/core/encryption/ZipCrypto.js +7 -0
  21. package/dist/neozipkit-wrappers/core/index.js +3 -0
  22. package/dist/neozipkit-wrappers/index.js +13 -0
  23. package/dist/neozipkit-wrappers/server/index.js +2 -0
  24. package/dist/src/config/ConfigSetup.js +455 -0
  25. package/dist/src/config/ConfigStore.js +373 -0
  26. package/dist/src/config/ConfigWizard.js +453 -0
  27. package/dist/src/config/WalletConfig.js +372 -0
  28. package/dist/src/exit-codes.js +210 -0
  29. package/dist/src/index.js +141 -0
  30. package/dist/src/neolist.js +1194 -0
  31. package/dist/src/neounzip.js +2177 -0
  32. package/dist/src/neozip/CommentManager.js +240 -0
  33. package/dist/src/neozip/blockchain.js +383 -0
  34. package/dist/src/neozip/createZip.js +2273 -0
  35. package/dist/src/neozip/file-operations.js +920 -0
  36. package/dist/src/neozip/types.js +6 -0
  37. package/dist/src/neozip/user-interaction.js +256 -0
  38. package/dist/src/neozip/utils.js +96 -0
  39. package/dist/src/neozip.js +785 -0
  40. package/dist/src/server/CommentManager.js +240 -0
  41. package/dist/src/version.js +59 -0
  42. package/env.example +101 -0
  43. package/package.json +175 -0
@@ -0,0 +1,453 @@
1
+ "use strict";
2
+ /**
3
+ * ConfigWizard - Interactive setup wizard for NeoZip wallet configuration
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ConfigWizard = void 0;
40
+ const readline = __importStar(require("readline"));
41
+ const WalletConfig_1 = require("./WalletConfig");
42
+ const contracts_1 = require('../../neozipkit-wrappers/blockchain/core/contracts');
43
+ class ConfigWizard {
44
+ constructor() {
45
+ this.rl = readline.createInterface({
46
+ input: process.stdin,
47
+ output: process.stdout,
48
+ });
49
+ }
50
+ /**
51
+ * Prompt for selection from a numbered list
52
+ */
53
+ async promptSelection(title, options, defaultValue) {
54
+ console.log(` ${title}`);
55
+ // Display options with numbers
56
+ options.forEach((opt, index) => {
57
+ const isDefault = opt.value === defaultValue;
58
+ const defaultTag = isDefault ? ' [DEFAULT]' : '';
59
+ const description = opt.description ? ` - ${opt.description}` : '';
60
+ console.log(` ${index + 1}. ${opt.label}${description}${defaultTag}`);
61
+ });
62
+ // Get default index
63
+ const defaultIndex = defaultValue
64
+ ? options.findIndex(opt => opt.value === defaultValue) + 1
65
+ : 1;
66
+ const answer = await this.prompt(' Enter choice', defaultIndex.toString());
67
+ const choice = parseInt(answer);
68
+ if (isNaN(choice) || choice < 1 || choice > options.length) {
69
+ console.error(` āŒ Invalid choice. Please select 1-${options.length}`);
70
+ return defaultValue || options[0].value;
71
+ }
72
+ return options[choice - 1].value;
73
+ }
74
+ /**
75
+ * Prompt for a value with validation
76
+ */
77
+ async prompt(question, defaultValue, isPassword = false) {
78
+ return new Promise((resolve) => {
79
+ const displayQuestion = defaultValue
80
+ ? `${question} (${defaultValue}): `
81
+ : `${question}: `;
82
+ if (isPassword) {
83
+ // For password input, use readline with line clearing for security
84
+ this.rl.question(displayQuestion, (answer) => {
85
+ // Clear the line to hide the password from terminal history
86
+ readline.clearLine(process.stdout, 0);
87
+ readline.cursorTo(process.stdout, 0);
88
+ process.stdout.write(question.split(':')[0] + ': ********\n');
89
+ resolve(answer.trim() || defaultValue || '');
90
+ });
91
+ }
92
+ else {
93
+ this.rl.question(displayQuestion, (answer) => {
94
+ resolve(answer.trim() || defaultValue || '');
95
+ });
96
+ }
97
+ });
98
+ }
99
+ /**
100
+ * Run the interactive setup wizard
101
+ */
102
+ async run() {
103
+ console.log('\nšŸ”§ NeoZip Wallet Configuration Setup\n');
104
+ console.log('This wizard will help you configure your blockchain wallet settings.');
105
+ console.log('Press Ctrl+C at any time to cancel.\n');
106
+ try {
107
+ // Load existing config if available
108
+ const existingConfig = WalletConfig_1.WalletConfig.load();
109
+ const isUpdate = existingConfig !== null;
110
+ if (isUpdate) {
111
+ console.log('šŸ“ Existing configuration found. You can update individual settings.\n');
112
+ }
113
+ // 1. Wallet Private Key
114
+ console.log('1ļøāƒ£ Wallet Configuration');
115
+ console.log(' Your private key is required for blockchain operations (minting, OTS).');
116
+ let privateKey;
117
+ if (isUpdate && existingConfig?.wallet?.privateKey) {
118
+ const masked = `${existingConfig.wallet.privateKey.substring(0, 6)}...${existingConfig.wallet.privateKey.substring(existingConfig.wallet.privateKey.length - 4)}`;
119
+ const keep = await this.promptSelection(`Keep existing private key (${masked})?`, [
120
+ { value: 'y', label: 'Yes', description: 'Keep current key' },
121
+ { value: 'n', label: 'No', description: 'Enter new key' }
122
+ ], 'y');
123
+ if (keep === 'y') {
124
+ privateKey = existingConfig.wallet.privateKey;
125
+ }
126
+ else {
127
+ privateKey = await this.prompt(' Enter wallet private key', '', true);
128
+ }
129
+ }
130
+ else {
131
+ privateKey = await this.prompt(' Enter wallet private key', '', true);
132
+ }
133
+ // Validate private key
134
+ if (privateKey && !WalletConfig_1.WalletConfig.validatePrivateKey(privateKey)) {
135
+ console.error('\nāŒ Invalid private key format. Must be 64 hex characters (with or without 0x prefix).');
136
+ this.rl.close();
137
+ return false;
138
+ }
139
+ // Ensure 0x prefix
140
+ if (privateKey && !privateKey.startsWith('0x')) {
141
+ privateKey = `0x${privateKey}`;
142
+ }
143
+ // 2. Network Selection
144
+ console.log('\n2ļøāƒ£ Network Selection');
145
+ const currentNetwork = existingConfig?.wallet?.network || 'base-sepolia';
146
+ // Dynamically build network options from CONTRACT_CONFIGS
147
+ // CONTRACT_CONFIGS is already ordered correctly: Base (testnet/mainnet), Arbitrum (testnet/mainnet), Ethereum
148
+ const networkOptions = [];
149
+ const networkConfigs = Object.values(contracts_1.CONTRACT_CONFIGS);
150
+ // Verify we're loading networks
151
+ if (networkConfigs.length === 0) {
152
+ console.error('āŒ Error: No networks found in CONTRACT_CONFIGS');
153
+ console.error(' This should not happen. Please check the contracts configuration.');
154
+ process.exit(1);
155
+ }
156
+ // Networks are already in the correct order from CONTRACT_CONFIGS (preserved by Object.values())
157
+ for (const config of networkConfigs) {
158
+ // Use the primary alias (first nameAlias) or network name as value
159
+ const primaryAlias = config.nameAliases && config.nameAliases.length > 0
160
+ ? config.nameAliases[0]
161
+ : (0, contracts_1.normalizeNetworkName)(config.network);
162
+ // Determine description based on network type
163
+ const isTestnet = config.network.toLowerCase().includes('testnet') ||
164
+ config.network.toLowerCase().includes('sepolia');
165
+ const description = isTestnet
166
+ ? `Testnet (Chain ID: ${config.chainId})`
167
+ : `Mainnet (Chain ID: ${config.chainId}) - Real ETH required`;
168
+ networkOptions.push({
169
+ value: primaryAlias,
170
+ label: config.network,
171
+ description: description
172
+ });
173
+ }
174
+ const network = await this.promptSelection('Choose your blockchain network:', networkOptions, currentNetwork);
175
+ // 3. Custom RPC (optional)
176
+ console.log('\n3ļøāƒ£ RPC Configuration (optional)');
177
+ const useCustomRpc = await this.promptSelection('Configure custom RPC endpoints?', [
178
+ { value: 'n', label: 'No', description: 'Use default public RPC endpoints' },
179
+ { value: 'y', label: 'Yes', description: 'Configure custom RPC URLs' }
180
+ ], 'n');
181
+ // Build RPC config dynamically from available networks
182
+ const rpcConfig = {};
183
+ // Preserve existing RPC config (for backward compatibility)
184
+ if (existingConfig?.rpc) {
185
+ Object.assign(rpcConfig, existingConfig.rpc);
186
+ }
187
+ if (useCustomRpc === 'y') {
188
+ // Get the selected network config to show default RPC
189
+ const selectedNetworkConfig = (0, contracts_1.getNetworkByName)(network);
190
+ // Prompt for RPC URL for the selected network
191
+ if (selectedNetworkConfig) {
192
+ const defaultRpc = selectedNetworkConfig.rpcUrls && selectedNetworkConfig.rpcUrls.length > 0
193
+ ? selectedNetworkConfig.rpcUrls[0]
194
+ : '';
195
+ // Use primary alias as RPC key for consistency (or normalized network name as fallback)
196
+ const rpcKey = (selectedNetworkConfig.nameAliases && selectedNetworkConfig.nameAliases.length > 0)
197
+ ? selectedNetworkConfig.nameAliases[0]
198
+ : (0, contracts_1.normalizeNetworkName)(selectedNetworkConfig.network);
199
+ // Check both new format and legacy format for backward compatibility
200
+ const existingRpc = rpcConfig[rpcKey]
201
+ || rpcConfig[(0, contracts_1.normalizeNetworkName)(selectedNetworkConfig.network).replace(/\s+/g, '')]
202
+ || existingConfig?.rpc?.[rpcKey]
203
+ || existingConfig?.rpc?.[(0, contracts_1.normalizeNetworkName)(selectedNetworkConfig.network).replace(/\s+/g, '')];
204
+ const customRpc = await this.prompt(` ${selectedNetworkConfig.network} RPC URL`, existingRpc || defaultRpc);
205
+ if (customRpc) {
206
+ rpcConfig[rpcKey] = customRpc;
207
+ }
208
+ }
209
+ // Optionally configure RPC for other networks
210
+ const configureMore = await this.promptSelection('Configure RPC for additional networks?', [
211
+ { value: 'n', label: 'No', description: 'Only configure selected network' },
212
+ { value: 'y', label: 'Yes', description: 'Configure all networks' }
213
+ ], 'n');
214
+ if (configureMore === 'y') {
215
+ for (const config of networkConfigs) {
216
+ // Skip the already configured network
217
+ const configAlias = config.nameAliases && config.nameAliases.length > 0
218
+ ? config.nameAliases[0]
219
+ : (0, contracts_1.normalizeNetworkName)(config.network);
220
+ if (configAlias === network)
221
+ continue;
222
+ // Use primary alias as RPC key for consistency (or normalized network name as fallback)
223
+ const rpcKey = (config.nameAliases && config.nameAliases.length > 0)
224
+ ? config.nameAliases[0]
225
+ : (0, contracts_1.normalizeNetworkName)(config.network);
226
+ const defaultRpc = config.rpcUrls && config.rpcUrls.length > 0
227
+ ? config.rpcUrls[0]
228
+ : '';
229
+ // Check both new format and legacy format for backward compatibility
230
+ const existingRpc = rpcConfig[rpcKey]
231
+ || rpcConfig[(0, contracts_1.normalizeNetworkName)(config.network).replace(/\s+/g, '')]
232
+ || existingConfig?.rpc?.[rpcKey]
233
+ || existingConfig?.rpc?.[(0, contracts_1.normalizeNetworkName)(config.network).replace(/\s+/g, '')];
234
+ const customRpc = await this.prompt(` ${config.network} RPC URL`, existingRpc || defaultRpc);
235
+ if (customRpc) {
236
+ rpcConfig[rpcKey] = customRpc;
237
+ }
238
+ }
239
+ }
240
+ }
241
+ // 4. Gas Configuration (optional)
242
+ console.log('\n4ļøāƒ£ Gas Configuration (optional)');
243
+ const configureGas = await this.promptSelection('Configure gas settings?', [
244
+ { value: 'n', label: 'No', description: 'Use default gas settings' },
245
+ { value: 'y', label: 'Yes', description: 'Configure custom gas limits' }
246
+ ], 'n');
247
+ let gasMultiplier = existingConfig?.gas?.multiplier;
248
+ let maxGasPrice = existingConfig?.gas?.maxPriceGwei;
249
+ if (configureGas === 'y') {
250
+ const multiplierStr = await this.prompt(' Gas price multiplier', gasMultiplier?.toString() || '1.0');
251
+ const maxPriceStr = await this.prompt(' Max gas price (gwei)', maxGasPrice?.toString() || '100');
252
+ gasMultiplier = parseFloat(multiplierStr);
253
+ maxGasPrice = parseInt(maxPriceStr);
254
+ }
255
+ // 5. Debug Settings (optional)
256
+ console.log('\n5ļøāƒ£ Debug Configuration (optional)');
257
+ const configureDebug = await this.promptSelection('Enable debug/verbose mode?', [
258
+ { value: 'n', label: 'No', description: 'Standard logging only' },
259
+ { value: 'y', label: 'Yes', description: 'Enable verbose and debug output' }
260
+ ], 'n');
261
+ let verbose = existingConfig?.debug?.verbose || false;
262
+ let debugEnabled = existingConfig?.debug?.enabled || false;
263
+ if (configureDebug === 'y') {
264
+ const verboseStr = await this.promptSelection('Enable verbose logging?', [
265
+ { value: 'n', label: 'No' },
266
+ { value: 'y', label: 'Yes' }
267
+ ], verbose ? 'y' : 'n');
268
+ const debugStr = await this.promptSelection('Enable debug mode?', [
269
+ { value: 'n', label: 'No' },
270
+ { value: 'y', label: 'Yes' }
271
+ ], debugEnabled ? 'y' : 'n');
272
+ verbose = verboseStr === 'y';
273
+ debugEnabled = debugStr === 'y';
274
+ }
275
+ // Build configuration object
276
+ const config = {
277
+ wallet: {
278
+ privateKey,
279
+ network,
280
+ },
281
+ rpc: Object.keys(rpcConfig).length > 0 ? rpcConfig : undefined,
282
+ gas: gasMultiplier || maxGasPrice ? {
283
+ multiplier: gasMultiplier,
284
+ maxPriceGwei: maxGasPrice,
285
+ } : undefined,
286
+ debug: verbose || debugEnabled ? {
287
+ verbose,
288
+ enabled: debugEnabled,
289
+ } : undefined,
290
+ };
291
+ // Save configuration
292
+ console.log('\nšŸ’¾ Saving configuration...');
293
+ const saved = WalletConfig_1.WalletConfig.save(config);
294
+ if (saved) {
295
+ console.log(`āœ… Configuration saved to: ${WalletConfig_1.WalletConfig.getConfigPath()}\n`);
296
+ console.log('šŸ“‹ Configuration summary:');
297
+ console.log(` Wallet: ${privateKey ? `${privateKey.substring(0, 6)}...${privateKey.substring(privateKey.length - 4)}` : '(not set)'}`);
298
+ console.log(` Network: ${network}`);
299
+ if (Object.keys(rpcConfig).length > 0) {
300
+ console.log(` RPC URLs: Custom (${Object.keys(rpcConfig).length} network(s))`);
301
+ }
302
+ if (gasMultiplier || maxGasPrice) {
303
+ console.log(` Gas: Custom (${gasMultiplier}x, max ${maxGasPrice} gwei)`);
304
+ }
305
+ if (verbose || debugEnabled) {
306
+ console.log(` Debug: ${verbose ? 'verbose' : ''} ${debugEnabled ? 'enabled' : ''}`);
307
+ }
308
+ console.log('\nšŸ’” You can now use blockchain features: neozip -b <archive> <files>');
309
+ console.log('šŸ’” To update config: neozip config show | set | reset\n');
310
+ }
311
+ this.rl.close();
312
+ return saved;
313
+ }
314
+ catch (error) {
315
+ console.error(`\nāŒ Setup failed: ${error}`);
316
+ this.rl.close();
317
+ return false;
318
+ }
319
+ }
320
+ /**
321
+ * Show configuration and offer options to modify or reset
322
+ */
323
+ static async showAndManage() {
324
+ if (!WalletConfig_1.WalletConfig.exists()) {
325
+ console.log('\nāš ļø No wallet.json configuration found.');
326
+ console.log('šŸ’” Run "neozip init" to create your configuration.\n');
327
+ process.exit(0);
328
+ }
329
+ console.log('\nšŸ“‹ Current NeoZip Configuration:');
330
+ console.log(`šŸ“ Location: ${WalletConfig_1.WalletConfig.getConfigPath()}\n`);
331
+ console.log(WalletConfig_1.WalletConfig.getMaskedConfig());
332
+ console.log('');
333
+ // Create readline interface for menu
334
+ const rl = require('readline').createInterface({
335
+ input: process.stdin,
336
+ output: process.stdout
337
+ });
338
+ return new Promise((resolve) => {
339
+ const showMenu = () => {
340
+ const config = WalletConfig_1.WalletConfig.getConfig();
341
+ const hasPrivateKey = config.walletKey !== null;
342
+ console.log('What would you like to do?');
343
+ console.log(' 1. Modify configuration (update settings)');
344
+ if (hasPrivateKey) {
345
+ console.log(' 2. Delete private key (remove wallet key from configuration)');
346
+ console.log(' 3. Reset to defaults (delete entire configuration)');
347
+ console.log(' 4. Exit');
348
+ }
349
+ else {
350
+ console.log(' 2. Reset to defaults (delete entire configuration)');
351
+ console.log(' 3. Exit');
352
+ }
353
+ const maxChoice = hasPrivateKey ? 4 : 3;
354
+ rl.question(`\nEnter choice (1-${maxChoice}): `, async (answer) => {
355
+ const choice = parseInt(answer);
356
+ switch (choice) {
357
+ case 1:
358
+ rl.close();
359
+ const wizard = new ConfigWizard();
360
+ const success = await wizard.run();
361
+ process.exit(success ? 0 : 1);
362
+ break;
363
+ case 2:
364
+ if (hasPrivateKey) {
365
+ // Delete private key only
366
+ rl.question('\nāš ļø Are you sure you want to delete your private key? (y/n): ', (confirm) => {
367
+ if (confirm.toLowerCase() === 'y') {
368
+ const success = WalletConfig_1.WalletConfig.delete('wallet.privateKey');
369
+ if (success) {
370
+ console.log('āœ… Private key deleted successfully.\n');
371
+ }
372
+ else {
373
+ console.log('āŒ Failed to delete private key.\n');
374
+ }
375
+ rl.close();
376
+ process.exit(success ? 0 : 1);
377
+ }
378
+ else {
379
+ console.log('āŒ Deletion cancelled.\n');
380
+ rl.close();
381
+ process.exit(0);
382
+ }
383
+ });
384
+ }
385
+ else {
386
+ // Reset entire config
387
+ rl.question('\nāš ļø Are you sure you want to delete your wallet configuration? (y/n): ', (confirm) => {
388
+ if (confirm.toLowerCase() === 'y') {
389
+ const success = WalletConfig_1.WalletConfig.reset();
390
+ if (success) {
391
+ console.log('āœ… Configuration deleted successfully.\n');
392
+ }
393
+ rl.close();
394
+ process.exit(success ? 0 : 1);
395
+ }
396
+ else {
397
+ console.log('āŒ Reset cancelled.\n');
398
+ rl.close();
399
+ process.exit(0);
400
+ }
401
+ });
402
+ }
403
+ break;
404
+ case 3:
405
+ if (hasPrivateKey) {
406
+ // Reset entire config
407
+ rl.question('\nāš ļø Are you sure you want to delete your wallet configuration? (y/n): ', (confirm) => {
408
+ if (confirm.toLowerCase() === 'y') {
409
+ const success = WalletConfig_1.WalletConfig.reset();
410
+ if (success) {
411
+ console.log('āœ… Configuration deleted successfully.\n');
412
+ }
413
+ rl.close();
414
+ process.exit(success ? 0 : 1);
415
+ }
416
+ else {
417
+ console.log('āŒ Reset cancelled.\n');
418
+ rl.close();
419
+ process.exit(0);
420
+ }
421
+ });
422
+ }
423
+ else {
424
+ // Exit
425
+ console.log('');
426
+ rl.close();
427
+ process.exit(0);
428
+ }
429
+ break;
430
+ case 4:
431
+ if (hasPrivateKey) {
432
+ // Exit
433
+ console.log('');
434
+ rl.close();
435
+ process.exit(0);
436
+ }
437
+ else {
438
+ console.log(`\nāŒ Invalid choice. Please select 1-${maxChoice}.\n`);
439
+ showMenu();
440
+ }
441
+ break;
442
+ default:
443
+ console.log(`\nāŒ Invalid choice. Please select 1-${maxChoice}.\n`);
444
+ showMenu();
445
+ }
446
+ });
447
+ };
448
+ showMenu();
449
+ });
450
+ }
451
+ }
452
+ exports.ConfigWizard = ConfigWizard;
453
+ //# sourceMappingURL=ConfigWizard.js.map