neozip-cli 0.70.0-alpha → 0.75.1-beta

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