How to parse ecrecover parameters?

by Sophie259   Last Updated September 10, 2019 21:28 PM - source

I am looking into getting the public key from ANY ethereum address (not owned by me) that has sent a transaction at least once. It seems that the most viable solution here would be to use ethereumjs-utils

 * ECDSA public key recovery from signature
 * @param {Buffer} msgHash
 * @param {Number} v
 * @param {Buffer} r
 * @param {Buffer} s
 * @return {Buffer} publicKey
exports.ecrecover = function (msgHash, v, r, s) {
  var signature = Buffer.concat([exports.setLength(r, 32), exports.setLength(s, 32)], 64)
  var recovery = v - 27
  if (recovery !== 0 && recovery !== 1) {
    throw new Error('Invalid signature v value')
  var senderPubKey = secp256k1.recover(msgHash, signature, recovery)
  return secp256k1.publicKeyConvert(senderPubKey, false).slice(1)

The user mentions that

when you send a transaction, you sign the transaction and it includes these v r and s values. You parse these from the signed tx and then pass these v r and s values and the has of the transaction back into a function and it'll spit out the public key

This last step is completely unclear to me. I do not understand how we parse "v", "r" and "s".

Picking a random transaction hash on, how are we going to "parse" the v,r and s parameters?

Related Questions

What is a block hash?

Updated December 13, 2017 04:28 AM

How does a message signed in Remix IDE

Updated February 28, 2019 06:28 AM