Can We Recover The Public Key from an ECDSA Signature?
With ECDSA we create a signature with a private key and then prove with a public key. A special feature of ECDSA is that we can recover the public key from the signature.
With ECDSA we have a signature value of (r,s,v) and we can use these values to recover the public key. In the following, we see an Ethereum transaction, and where the r, s, and v values are stored with the transaction:
In this case, we will create a random private key, and then derive the public key. Next, we will generate an ECDSA signature for a given data value, and then recover the public key using two methods (SigToPub and Ecrecover) from github.com/ethereum/go-ethereum/crypto.
The following code is used to create a SHA-3 hash from the data, and then sign with the private key:
hash := crypto.Keccak256Hash(data)
fmt.Printf("Hash: %x\n", hash.Bytes())