-
-
Save ulinkwo/656e3c1bcd8aa6c7ae1676cc96537dcd 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 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