-
Notifications
You must be signed in to change notification settings - Fork 1
/
privateKeyHelper.js
40 lines (34 loc) · 1.18 KB
/
privateKeyHelper.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
36
37
38
39
40
module.exports = new Promise(resolve => {
const path = require('path');
const readline = require("readline");
var Writable = require('stream').Writable;
var mutableStdout = new Writable({
write: function (chunk, encoding, callback) {
if (!this.muted)
process.stdout.write(chunk, encoding);
callback();
}
});
mutableStdout.muted = false;
var rl = readline.createInterface({
input: process.stdin,
output: mutableStdout,
terminal: true
});
let gpg = require('./scripts/gpgRuntime/gpg.js')
let fPath = path.join(__dirname, `./keyStore.json.gpg`)
rl.question("please type your encryption key: ", function (password) {
rl.close();
gpg.call(password, ['--skip-verify', '--passphrase-fd', '0', '--decrypt', fPath], (err, res) => {
if (err) {
console.log("\nerror: decryption failed")
} else {
console.log("\ndecryption successful")
resolve({
PRIVATE_KEY: JSON.parse(res.toString('utf8')).key
})
}
});
});
mutableStdout.muted = true;
})