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,373 @@
1
+ "use strict";
2
+ /**
3
+ * ConfigStore - Configuration storage and retrieval manager for NeoZip
4
+ * Handles wallet.json file I/O, environment variable resolution, and config validation
5
+ * This is the data layer - handles all config storage/retrieval operations
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.ConfigStore = void 0;
42
+ const fs = __importStar(require("fs"));
43
+ const path = __importStar(require("path"));
44
+ const os = __importStar(require("os"));
45
+ const contracts_1 = require('../../neozipkit-wrappers/blockchain/core/contracts');
46
+ const DEFAULTS = {
47
+ network: 'base-sepolia',
48
+ rpcUrls: {
49
+ baseSepolia: 'https://sepolia.base.org',
50
+ baseMainnet: 'https://mainnet.base.org',
51
+ },
52
+ gas: {
53
+ multiplier: 1.0,
54
+ maxPriceGwei: 100,
55
+ },
56
+ debug: {
57
+ verbose: false,
58
+ enabled: false,
59
+ },
60
+ };
61
+ class ConfigStore {
62
+ /**
63
+ * Get the configuration directory path
64
+ */
65
+ static getConfigDir() {
66
+ return this.configDir;
67
+ }
68
+ /**
69
+ * Get the configuration file path
70
+ */
71
+ static getConfigPath() {
72
+ return this.configPath;
73
+ }
74
+ /**
75
+ * Check if wallet.json exists
76
+ */
77
+ static exists() {
78
+ return fs.existsSync(this.getConfigPath());
79
+ }
80
+ /**
81
+ * Load configuration from wallet.json
82
+ */
83
+ static load() {
84
+ if (!this.exists()) {
85
+ return null;
86
+ }
87
+ try {
88
+ const content = fs.readFileSync(this.getConfigPath(), 'utf-8');
89
+ return JSON.parse(content);
90
+ }
91
+ catch (error) {
92
+ console.error(`⚠️ Failed to load wallet.json: ${error}`);
93
+ return null;
94
+ }
95
+ }
96
+ /**
97
+ * Save configuration to wallet.json
98
+ */
99
+ static save(config) {
100
+ try {
101
+ // Ensure config directory exists
102
+ const configDir = this.getConfigDir();
103
+ if (!fs.existsSync(configDir)) {
104
+ fs.mkdirSync(configDir, { recursive: true, mode: 0o700 });
105
+ }
106
+ // Write config file with restricted permissions
107
+ fs.writeFileSync(this.getConfigPath(), JSON.stringify(config, null, 2), { mode: 0o600 });
108
+ return true;
109
+ }
110
+ catch (error) {
111
+ console.error(`❌ Failed to save wallet.json: ${error}`);
112
+ return false;
113
+ }
114
+ }
115
+ /**
116
+ * Delete wallet.json configuration
117
+ */
118
+ static reset() {
119
+ try {
120
+ if (this.exists()) {
121
+ fs.unlinkSync(this.getConfigPath());
122
+ }
123
+ return true;
124
+ }
125
+ catch (error) {
126
+ console.error(`❌ Failed to delete wallet.json: ${error}`);
127
+ return false;
128
+ }
129
+ }
130
+ /**
131
+ * Get resolved configuration with precedence: CLI args > ENV vars > wallet.json > defaults
132
+ * @param cliWalletKey - Wallet key from CLI argument (highest priority)
133
+ */
134
+ static getConfig(cliWalletKey) {
135
+ const jsonConfig = this.load();
136
+ // Wallet key precedence: CLI > ENV > wallet.json
137
+ let walletKey = null;
138
+ if (cliWalletKey) {
139
+ walletKey = cliWalletKey;
140
+ }
141
+ else if (process.env.NEOZIP_WALLET_PASSKEY) {
142
+ walletKey = process.env.NEOZIP_WALLET_PASSKEY;
143
+ }
144
+ else if (jsonConfig?.wallet?.privateKey) {
145
+ walletKey = jsonConfig.wallet.privateKey;
146
+ }
147
+ // Network precedence: ENV > wallet.json > default
148
+ const network = process.env.NEOZIP_NETWORK ||
149
+ jsonConfig?.wallet?.network ||
150
+ DEFAULTS.network;
151
+ // RPC URLs precedence: ENV > wallet.json > default
152
+ const rpcUrls = {
153
+ baseSepolia: process.env.NEOZIP_BASE_SEPOLIA_RPC_URL ||
154
+ jsonConfig?.rpc?.baseSepolia ||
155
+ DEFAULTS.rpcUrls.baseSepolia,
156
+ baseMainnet: process.env.NEOZIP_BASE_MAINNET_RPC_URL ||
157
+ jsonConfig?.rpc?.baseMainnet ||
158
+ DEFAULTS.rpcUrls.baseMainnet,
159
+ };
160
+ // Gas settings precedence: ENV > wallet.json > default
161
+ const gas = {
162
+ multiplier: process.env.NEOZIP_GAS_MULTIPLIER ?
163
+ parseFloat(process.env.NEOZIP_GAS_MULTIPLIER) :
164
+ jsonConfig?.gas?.multiplier ||
165
+ DEFAULTS.gas.multiplier,
166
+ maxPriceGwei: process.env.NEOZIP_MAX_GAS_PRICE ?
167
+ parseInt(process.env.NEOZIP_MAX_GAS_PRICE) :
168
+ jsonConfig?.gas?.maxPriceGwei ||
169
+ DEFAULTS.gas.maxPriceGwei,
170
+ };
171
+ // Debug settings precedence: ENV > wallet.json > default
172
+ const debug = {
173
+ verbose: process.env.NEOZIP_VERBOSE === 'true' ||
174
+ jsonConfig?.debug?.verbose ||
175
+ DEFAULTS.debug.verbose,
176
+ enabled: process.env.NEOZIP_DEBUG === 'true' ||
177
+ jsonConfig?.debug?.enabled ||
178
+ DEFAULTS.debug.enabled,
179
+ };
180
+ return {
181
+ walletKey,
182
+ network,
183
+ rpcUrls,
184
+ gas,
185
+ debug,
186
+ };
187
+ }
188
+ /**
189
+ * Validate wallet private key format
190
+ */
191
+ static validatePrivateKey(key) {
192
+ // Must be 66 characters (0x + 64 hex chars) or 64 characters (without 0x)
193
+ const withPrefix = /^0x[0-9a-fA-F]{64}$/;
194
+ const withoutPrefix = /^[0-9a-fA-F]{64}$/;
195
+ return withPrefix.test(key) || withoutPrefix.test(key);
196
+ }
197
+ /**
198
+ * Validate network name (uses nameAliases from CONTRACT_CONFIGS)
199
+ */
200
+ static validateNetwork(network) {
201
+ return (0, contracts_1.getChainIdByName)(network) !== null;
202
+ }
203
+ /**
204
+ * Update a specific configuration value
205
+ */
206
+ static set(key, value) {
207
+ let config = this.load() || {
208
+ wallet: {},
209
+ rpc: {},
210
+ gas: {},
211
+ debug: {},
212
+ };
213
+ // Parse the key path (e.g., "wallet.privateKey", "gas.multiplier")
214
+ const parts = key.split('.');
215
+ switch (parts[0]) {
216
+ case 'wallet':
217
+ if (parts[1] === 'privateKey') {
218
+ if (!this.validatePrivateKey(value)) {
219
+ console.error('❌ Invalid private key format');
220
+ return false;
221
+ }
222
+ config.wallet.privateKey = value.startsWith('0x') ? value : `0x${value}`;
223
+ }
224
+ else if (parts[1] === 'network') {
225
+ if (!this.validateNetwork(value)) {
226
+ const supportedNetworks = (0, contracts_1.getSupportedNetworkNames)();
227
+ console.error(`❌ Invalid network: "${value}"`);
228
+ console.error(`Supported networks: ${supportedNetworks.join(', ')}`);
229
+ return false;
230
+ }
231
+ config.wallet.network = value;
232
+ }
233
+ break;
234
+ case 'rpc':
235
+ if (!config.rpc)
236
+ config.rpc = {};
237
+ // Support both legacy keys and dynamic network keys
238
+ if (parts[1] === 'baseSepolia') {
239
+ config.rpc.baseSepolia = value;
240
+ }
241
+ else if (parts[1] === 'baseMainnet') {
242
+ config.rpc.baseMainnet = value;
243
+ }
244
+ else {
245
+ // Allow dynamic network keys (e.g., "rpc.baseSepolia", "rpc.arbitrumSepolia")
246
+ config.rpc[parts[1]] = value;
247
+ }
248
+ break;
249
+ case 'gas':
250
+ if (!config.gas)
251
+ config.gas = {};
252
+ if (parts[1] === 'multiplier') {
253
+ config.gas.multiplier = parseFloat(value);
254
+ }
255
+ else if (parts[1] === 'maxPriceGwei') {
256
+ config.gas.maxPriceGwei = parseInt(value);
257
+ }
258
+ break;
259
+ case 'debug':
260
+ if (!config.debug)
261
+ config.debug = {};
262
+ if (parts[1] === 'verbose') {
263
+ config.debug.verbose = value === 'true';
264
+ }
265
+ else if (parts[1] === 'enabled') {
266
+ config.debug.enabled = value === 'true';
267
+ }
268
+ break;
269
+ default:
270
+ console.error(`❌ Unknown configuration key: ${key}`);
271
+ return false;
272
+ }
273
+ return this.save(config);
274
+ }
275
+ /**
276
+ * Delete a specific configuration key
277
+ */
278
+ static delete(key) {
279
+ const config = this.load();
280
+ if (!config) {
281
+ console.error('❌ No configuration found');
282
+ return false;
283
+ }
284
+ // Parse the key path (e.g., "wallet.privateKey", "gas.multiplier")
285
+ const parts = key.split('.');
286
+ switch (parts[0]) {
287
+ case 'wallet':
288
+ if (parts[1] === 'privateKey') {
289
+ delete config.wallet.privateKey;
290
+ }
291
+ else if (parts[1] === 'network') {
292
+ delete config.wallet.network;
293
+ }
294
+ else {
295
+ console.error(`❌ Unknown wallet key: ${parts[1]}`);
296
+ return false;
297
+ }
298
+ break;
299
+ case 'rpc':
300
+ if (!config.rpc) {
301
+ console.error('❌ No RPC configuration found');
302
+ return false;
303
+ }
304
+ // Support both legacy keys and dynamic network keys
305
+ if (parts[1] === 'baseSepolia' || parts[1] === 'baseMainnet' || parts[1] in config.rpc) {
306
+ delete config.rpc[parts[1]];
307
+ }
308
+ else {
309
+ console.error(`❌ Unknown RPC key: ${parts[1]}`);
310
+ return false;
311
+ }
312
+ break;
313
+ case 'gas':
314
+ if (!config.gas) {
315
+ console.error('❌ No gas configuration found');
316
+ return false;
317
+ }
318
+ if (parts[1] === 'multiplier') {
319
+ delete config.gas.multiplier;
320
+ }
321
+ else if (parts[1] === 'maxPriceGwei') {
322
+ delete config.gas.maxPriceGwei;
323
+ }
324
+ else {
325
+ console.error(`❌ Unknown gas key: ${parts[1]}`);
326
+ return false;
327
+ }
328
+ break;
329
+ case 'debug':
330
+ if (!config.debug) {
331
+ console.error('❌ No debug configuration found');
332
+ return false;
333
+ }
334
+ if (parts[1] === 'verbose') {
335
+ delete config.debug.verbose;
336
+ }
337
+ else if (parts[1] === 'enabled') {
338
+ delete config.debug.enabled;
339
+ }
340
+ else {
341
+ console.error(`❌ Unknown debug key: ${parts[1]}`);
342
+ return false;
343
+ }
344
+ break;
345
+ default:
346
+ console.error(`❌ Unknown configuration key: ${key}`);
347
+ return false;
348
+ }
349
+ return this.save(config);
350
+ }
351
+ /**
352
+ * Get a masked version of the config for display (hides sensitive data)
353
+ */
354
+ static getMaskedConfig() {
355
+ const config = this.getConfig();
356
+ const masked = {
357
+ wallet: {
358
+ privateKey: config.walletKey ?
359
+ `${config.walletKey.substring(0, 6)}...${config.walletKey.substring(config.walletKey.length - 4)}` :
360
+ '(not set)',
361
+ network: config.network,
362
+ },
363
+ rpc: config.rpcUrls,
364
+ gas: config.gas,
365
+ debug: config.debug,
366
+ };
367
+ return JSON.stringify(masked, null, 2);
368
+ }
369
+ }
370
+ exports.ConfigStore = ConfigStore;
371
+ ConfigStore.configDir = path.join(os.homedir(), '.neozip');
372
+ ConfigStore.configPath = path.join(ConfigStore.configDir, 'wallet.json');
373
+ //# sourceMappingURL=ConfigStore.js.map