Last active
August 3, 2017 22:57
-
-
Save clowestab/46f451455d897262e6460202ed855411 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Include and initialise web3 | |
var Web3 = require("web3") | |
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); | |
//Output the current block number (to check things are working) | |
web3.eth.blockNumber | |
//Output a list of accounts. On a new Parity node this will be empty [] | |
web3.eth.accounts | |
//Include the keytherum library | |
var keythereum = require("keythereum"); | |
//Define some options/config | |
var password = "wheethereum"; | |
var kdf = "pbkdf2"; | |
var options = { | |
kdf: "pbkdf2", | |
cipher: "aes-128-ctr", | |
kdfparams: { | |
c: 262144, | |
dklen: 32, | |
prf: "hmac-sha256" | |
} | |
}; | |
//The unencrypted private key that MyEtherWallet displayed to us | |
var privateKey="0065c0e3b3da40d985e8467e5a9e2cfaa1627b55ca7d1ec2cd13a3c0a25d784f"; | |
//Require complex cryptography library | |
var ecdsa = new (require("elliptic").ec)("secp256k1"); | |
//Convert the private key to its public key counterpart | |
var publicKey = new Buffer(ecdsa.keyFromPrivate(privateKey).getPublic("arr")); | |
//Require the utility library for converting a public key to an address hex | |
var pubToAddress = require("ethereumjs-util").pubToAddress; | |
//Use it | |
var address = pubToAddress(publicKey).toString("hex"); | |
//At this point you can print out the address, and verify that it matches what you started with in Icebox. | |
//Next I want to produce a keystore file for Mist/Parity | |
//I wasn't sure how to make a salt and a Initialisation Vector. | |
//My understanding is that they are random and play a part in the crypto security of this all. | |
//I use keythereums create method and steal the salt/IV from there. | |
//Can someone more knowledgable confirm that this is OK? :P | |
var dk = keythereum.create(); | |
//I build the keystore file contents | |
var key = keythereum.dump(password, privateKey, dk.salt, dk.iv); | |
//And convert it to JSON | |
var jsonKey = JSON.stringify(key); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment