-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·31 lines (28 loc) · 1.03 KB
/
index.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
#!/usr/bin/env node --harmony
var program = require('commander');
var co = require('co');
var prompt = require('co-prompt');
var eosEcc = require('eosjs-ecc');
var eth = require('ethereumjs-util');
console.log("---KEYSWITCH: Ethereum to EOS key conversion---\n\n")
program
.action(function() {
co(function *() {
var ethKey = yield prompt('Ethereum private key: ');
var ethBuffer = Buffer.from(ethKey, 'hex');
if(eth.isValidPrivate(ethBuffer)) {
var ethPublic = "0x" + eth.privateToAddress(ethBuffer).toString('hex')
var eosWif = eosEcc.PrivateKey(ethBuffer).toWif()
var eosPublic = eosEcc.privateToPublic(eosWif);
console.log("**** IMPORTANT - Confirm ETH Address BELOW ****")
console.log("Ethereum Address: %s", ethPublic)
console.log("EOS Private Key: %s", eosWif);
console.log("EOS Public Key: %s", eosPublic);
process.exit(0);
} else {
console.log("Invalid Ethereum PrivateKey");
process.exit(0);
}
})
})
.parse(process.argv);