@vita-mojo/aggregator 1.8.0 ā 1.9.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/main.js.enc +0 -0
- package/main.js.map.enc +0 -0
- package/package.json +2 -2
- package/postinstall.js +90 -0
package/main.js.enc
CHANGED
|
Binary file
|
package/main.js.map.enc
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vita-mojo/aggregator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"postinstall": "
|
|
6
|
+
"postinstall": "node postinstall.js"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@vita-mojo/amounts": "0.0.33",
|
package/postinstall.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const crypto = require('crypto');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Decrypt a file using a shared secret
|
|
10
|
+
*/
|
|
11
|
+
function decryptFile(filePath, sharedSecret) {
|
|
12
|
+
const encryptedData = fs.readFileSync(filePath);
|
|
13
|
+
|
|
14
|
+
// Extract IV from the first 16 bytes
|
|
15
|
+
const iv = encryptedData.slice(0, 16);
|
|
16
|
+
const encrypted = encryptedData.slice(16);
|
|
17
|
+
|
|
18
|
+
// Decrypt the file content with AES-256-CBC using the shared secret
|
|
19
|
+
const decipher = crypto.createDecipheriv('aes-256-cbc', sharedSecret, iv);
|
|
20
|
+
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
21
|
+
|
|
22
|
+
return decrypted;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Decrypt all .enc files in the current directory
|
|
27
|
+
*/
|
|
28
|
+
function decryptFiles() {
|
|
29
|
+
console.log('\nš Decrypting aggregator files...');
|
|
30
|
+
|
|
31
|
+
const sharedSecretEnv = process.env.AGGREGATOR_ENCRYPTION_KEY;
|
|
32
|
+
if (!sharedSecretEnv) {
|
|
33
|
+
console.warn('ā AGGREGATOR_ENCRYPTION_KEY environment variable not set');
|
|
34
|
+
console.warn('ā Skipping decryption of aggregator files');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Shared secret must be 32 bytes (256 bits) for AES-256
|
|
39
|
+
const sharedSecret = Buffer.from(sharedSecretEnv, 'utf8');
|
|
40
|
+
if (sharedSecret.length !== 32) {
|
|
41
|
+
throw new Error(`AGGREGATOR_ENCRYPTION_KEY must be 32 bytes (256 bits), got ${sharedSecret.length} bytes`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Get current directory (where the package is installed)
|
|
45
|
+
const currentDir = __dirname;
|
|
46
|
+
|
|
47
|
+
if (!fs.existsSync(currentDir)) {
|
|
48
|
+
console.log(`ā Directory not found: ${currentDir}`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const files = fs.readdirSync(currentDir);
|
|
53
|
+
let decryptedCount = 0;
|
|
54
|
+
|
|
55
|
+
for (const file of files) {
|
|
56
|
+
if (!file.endsWith('.enc')) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const encFilePath = path.join(currentDir, file);
|
|
61
|
+
const originalFilePath = encFilePath.slice(0, -4); // Remove .enc extension
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const decrypted = decryptFile(encFilePath, sharedSecret);
|
|
65
|
+
fs.writeFileSync(originalFilePath, decrypted);
|
|
66
|
+
fs.unlinkSync(encFilePath); // Remove encrypted file
|
|
67
|
+
console.log(` ā Decrypted: ${path.basename(originalFilePath)}`);
|
|
68
|
+
decryptedCount++;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(`Failed to decrypt ${file}:`, error.message);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (decryptedCount === 0) {
|
|
76
|
+
console.log('No encrypted files found');
|
|
77
|
+
} else {
|
|
78
|
+
console.log(`ā Decryption completed (${decryptedCount} files)`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Main execution
|
|
84
|
+
*/
|
|
85
|
+
try {
|
|
86
|
+
decryptFiles();
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('\nā Aggregator decryption failed:', error.message);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|