1

I am using ganache blockchain, I want to verify that this is the key of a specific address.

Address : 0x24Ff3B7cacCcd9D05353dFB0Ff5b22062A13FbE0
Key : c28b71d6d57239ae0a575c5f5f4e7837092238c73eaaaa5e2b5e01c42714a1ed

I want to recover my address using this key to check that the key belongs to that particular address.

  • 1
    Question is not clear, You want to do it with web3 only or you are also using contract in the process. – Satyam Agrawal Jun 21 '18 at 7:29
  • You can't get a private key from a signature! Public address is built from the private key, so to find it you would have to find the private key first. Also what do you mean by validating your account? What do you try to achieve in the end? – Nicolas Massart Jun 21 '18 at 7:59
  • i want to use my private key as an password whose username is account or public key – Rahul sharma Jun 25 '18 at 8:28
1

An easy way to locally check if the public address belongs to the private key is to use nodejs and ethereumjs-wallet.

var ethjsWallet = require("ethereumjs-wallet");
var wallet = ethjsWallet.fromPrivateKey(yourPrivateKey)
var address = wallet.getAddress()

If you want to recover the public address from a signature, then you can use something like ethereumjs-utils. With ecrecover, you can recover the public key and from there on you can convert the public key to the public address.

  • i used your implementation var bufStr="c28b71d6d57239ae0a575c5f5f4e7837092238c73eaaaa5e2b5e01c42714a1ed"; var buf = Buffer.from(bufStr, 'utf8'); console.log(buf); var ethjsWallet = require("ethereumjs-wallet"); var wallet = ethjsWallet.fromPrivateKey(buf) var address = wallet.getAddress() – Rahul sharma Jun 25 '18 at 6:55
  • and got error : srajan@srajan-virtual-machine ~ $ node test.js <Buffer 63 32 38 62 37 31 64 36 64 35 37 32 33 39 61 65 30 61 35 37 35 63 35 66 35 66 34 65 37 38 33 37 30 39 32 32 33 38 63 37 33 65 61 61 61 61 35 65 32 62 ... > /home/srajan/node_modules/ethereumjs-wallet/index.js:23 throw new Error('Private key does not satisfy the curve requirements (ie. it is invalid)') – Rahul sharma Jun 25 '18 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.