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 Etherscan.io, how are we going to "parse" the v,r and s parameters?