Created
June 15, 2018 04:45
-
-
Save miracle2k/3012de6f7bbc3b0d3f390d273c01bf89 to your computer and use it in GitHub Desktop.
Convert Ethereum private keys to EOS private keys (the "Fallback method" to access your EOS tokens).
This file contains hidden or 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
// Extracted from https://github.com/eoscafe/eoskeyio | |
const ecc = require('eosjs-ecc'); | |
const eth = require('ethereumjs-util'); | |
let ethereumPrivateKey = 'FILL THIS IN'; | |
if(eth.isValidPrivate(Buffer.from(ethereumPrivateKey, 'hex'))) { | |
let ethereumAddress = '0x' + eth.privateToAddress(Buffer.from(ethereumPrivateKey, 'hex')).toString('hex') | |
let ethereumPublicKey = eth.privateToPublic(Buffer.from(ethereumPrivateKey, 'hex')).toString('hex') | |
// Create EOS keys | |
let eosWIF = ecc.PrivateKey(Buffer.from(ethereumPrivateKey, 'hex')).toWif() | |
let convertedEOSPrivateKey = eosWIF | |
let convertedEOSPublicKey = ecc.privateToPublic(eosWIF) | |
console.log(`EOS Private Key: ${convertedEOSPrivateKey}`) | |
console.log(`EOS Public Key: ${convertedEOSPublicKey}`) | |
} else { | |
console.log("Invalid Ethereum Private Key") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment