Skip to content

Commit 8ccebee

Browse files
committed
Add support for Geth
1 parent 171722e commit 8ccebee

8 files changed

+991
-82
lines changed

cli.js

+13-19
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,35 @@ const fs = require("fs");
44
const { join } = require("path");
55
const { spawnSync } = require("child_process");
66
const program = require("commander");
7-
const run = require("./main");
7+
const run = require("./main2");
88

99
const HOMEDIR = join(require("os").homedir(), ".parity-dev");
1010
const PARITY_BIN = join(HOMEDIR, "parity");
1111

1212
var noAction = true;
1313

14-
function setup() {
15-
try {
16-
fs.mkdirSync(HOMEDIR);
17-
} catch (err) {
18-
if (err.code !== "EEXIST") throw err;
19-
}
20-
21-
if (!fs.existsSync(PARITY_BIN)) {
22-
console.log("Download latest Parity version, please wait");
23-
spawnSync(join(__dirname, "get_parity.sh"), { stdio: "inherit" });
24-
}
25-
}
26-
2714
program
2815
.version("0.0.1")
2916
.option("-w, --workdir <dir>", "Specify a working dir.", "parity-data");
3017

3118
program
32-
.command("run")
33-
.description("Run Parity in development mode.")
19+
.command("parity")
20+
.description("Run a Parity development node.")
21+
.action(cmd => {
22+
noAction = false;
23+
run("parity", program.workdir);
24+
});
25+
26+
program
27+
.command("geth")
28+
.description("Run a Geth development node.")
3429
.action(cmd => {
3530
noAction = false;
36-
run(program.workdir);
31+
run("geth", program.workdir);
3732
});
3833

39-
setup();
4034
program.parse(process.argv);
4135

4236
if (noAction) {
43-
run(program.workdir);
37+
run("geth", program.workdir);
4438
}

crypto.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
const secp256k1 = require("secp256k1");
5+
const keythereum = require("keythereum");
6+
const { sha3, bytesToHex } = require("web3-utils");
7+
8+
function getKeypair(keyObject, password) {
9+
const privateKey = keythereum.recover(password, keyObject);
10+
const publicKey = secp256k1.publicKeyCreate(privateKey, false).slice(1, 65);
11+
return {
12+
address: "0x" + sha3(bytesToHex(publicKey)).slice(-40),
13+
privateKey: bytesToHex(privateKey)
14+
};
15+
}
16+
17+
function getKeypairs(keysDir, password) {
18+
return fs
19+
.readdirSync(keysDir)
20+
.filter(filename => filename.startsWith("UTC--"))
21+
.map(filename => JSON.parse(fs.readFileSync(path.join(keysDir, filename))))
22+
.map(keyObject => getKeypair(keyObject, password));
23+
}
24+
25+
module.exports = {
26+
getKeypair: getKeypair,
27+
getKeypairs: getKeypairs
28+
};

0 commit comments

Comments
 (0)