1

I find it hard to believe that something like this is not possible, as the use of public/private keys is a major bonus of digital identities.

I need to write a Javascript function to take in an ethereum address and return its public key. I know how to get the public key from a signature, but it is harder than I thought to get a transaction signature, web3 cannot return one I believe.

Can I use something in ParityJS to grab a transaction hash from input address account, and get the signature from it?

Someone please tell me this is possible, I am losing hope...

2

You can only recover a public key if you have a signature. The most common place to find a signature is from a transaction, so you would need to find a transaction made from that account. This is the hard step, because to my knowledge there's no easy "get me the list of transactions from this account" API. You'd need to search through the transactions in a range of blocks to find a transaction.

From there, you would just call eth_getTranscationByHash and then recover the public key from the signature (r, s, and v values).

  • Thanks for the input, although that function does not return a transaction signature... I have thought about maybe trying to do some sort of backend hack by going to the etherscan url of the input eth address, and the nparsing to find a transaction hash. But that still doesn't solve that transaction signatures are not saved and returned by getTransaction functions – 1pocketaces1 Mar 13 '18 at 19:49
  • It most certainly does return the signature: curl https://mainnet.infura.io -d '{"json_rpc": "2.0", "method": "eth_getTransactionByHash", "params": ["0x1ac7fead8f71a41c9aad091c92e76947a35c4a5fd3aa27e67d7db85b14b1dbd6"], "id": 0}'. (Just a random transaction I saw on etherscan.io just now.) – smarx Mar 13 '18 at 19:51
  • web3.eth.getTransaction('0x1ac7fead8f71a41c9aad091c92e76947a35c4a5fd3aa27e67d7db85b14b1dbd6', console.log); if you're using web3.js. – smarx Mar 13 '18 at 19:52
  • Etherscan's API looks like it will list transactions for you: etherscan.io/apis#accounts. If you're willing to rely on that API, that together with eth_getTransactionByHash and a ethereumjs-util to do the ecrecover should be sufficient. – smarx Mar 13 '18 at 19:55
  • Awesome thanks I will try that! I was thinking of web3's getTransaction(). Would you then know the answer to my next question can Metamask with web3 be used to access the private key for decryption the same way it is used for signing? – 1pocketaces1 Mar 15 '18 at 6:58
0

Address is generated from public key and it's a one way process. So it's not possible to generate a public key from an address

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.