Skip to content

Instantly share code, notes, and snippets.

@miracle2k
Created June 15, 2018 04:45
Show Gist options
  • Save miracle2k/3012de6f7bbc3b0d3f390d273c01bf89 to your computer and use it in GitHub Desktop.
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).
// 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