-
Notifications
You must be signed in to change notification settings - Fork 2
/
decrypt.js
executable file
·35 lines (32 loc) · 1 KB
/
decrypt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const crypto = require('crypto');
const key = process.env['MAGICLEAP'];
if (key) {
console.warn('Decrypting magicleap module with MAGICLEAP environment variable');
const ws = fs.createReadStream(path.join(__dirname, 'lib.zip.enc'))
.pipe(crypto.createDecipher('aes-256-cbc', Buffer.from(key, 'base64')))
.pipe(fs.createWriteStream(path.join(__dirname, 'lib.zip')));
ws.on('close', () => {
fs.unlink(path.join(__dirname, 'lib.zip.enc'), err => {
if (err && err.code !== 'ENOENT') {
console.warn(err);
}
process.exit(0);
});
});
ws.on('error', err => {
console.warn(err.stack);
process.exit(1);
});
} else {
console.warn('NOT decrypting magicleap module because MAGICLEAP environment variable not defined');
fs.unlink(path.join(__dirname, 'lib.zip.enc'), err => {
if (err && err.code !== 'ENOENT') {
console.warn(err);
}
process.exit(0);
});
process.exit(1);
}