forked from poanetwork/poa-test-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetPrivateInitialKeys.js
45 lines (40 loc) · 1.39 KB
/
getPrivateInitialKeys.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
41
42
43
44
45
const dir = require('node-dir');
const Constants = require("./utils/constants");
const constants = Constants.constants;
const keythereum = require("keythereum");
const path = require('path');
const fs = require('fs');
main()
function main() {
let initial_keys = {};
dir.readFiles(constants.scriptsMocOutputFolder,
function(err, content, filepath, next) {
let filename = path.basename(filepath)
if (filename == '.gitkeep' && filename != ".DS_Store") {
return next();
}
let key = path.parse(filename).name;
if (!initial_keys[key])
initial_keys[key] = {};
if (filename.includes(".json")) {
let keyStore = content;
initial_keys[key].keyStore = keyStore;
} else if (filename.includes(".key")) {
initial_keys[key].password = content
}
if (initial_keys[key].password && initial_keys[key].keyStore)
initial_keys[key].privateKey = keythereum.recover(initial_keys[key].password, JSON.parse(initial_keys[key].keyStore)).toString('hex');
if (err) throw err;
next();
},
function(err, files){
for (let initial_key in initial_keys) {
let keyObj = {
address: `0x${initial_key}`,
privateKey: initial_keys[initial_key].privateKey
}
fs.writeFileSync(`${constants.initialKeysFolder}${keyObj.address}`, JSON.stringify(keyObj, null, 2));
}
}
);
}