The question of signing and verifying signatures with Solidity has been asked in these questions, both of which I have tried to study:
How can I sign a piece of data with the private key of an Ethereum address?
How can I verify a cryptographic signature that was produced by an Ethereum address key pair
However, there are still pieces of information that I appear to be missing.
First off, I would like to start with the question about signing. In the example, the string Schoolbus
is signed by the address 0xd1ade25ccd3d550a7eb532ac759cac7be09c2719
, and the resulting signature is 0x2ac19db245478a06032e69cdbd2b54e648b78431d0a47bd1fbab18f79f820ba407466e37adbe9e84541cab97ab7d290f4a64a5825c876d22109f3bf813254e8601
.
So far, so good. Now, what I'd like to do is verify using ecrecover
that the signature is indeed correct for the given address and datum. The thing is, ecrecover
takes four arguments: ecrecover(h, v, r, s)
. Aside from h
being the hash, and {v, r, s}
somehow comprising the signature, what exactly do v, r, and s stand for? And how do I obtain all the values necessary from the single string 0x2ac19db245478a06032e69cdbd2b54e648b78431d0a47bd1fbab18f79f820ba407466e37adbe9e84541cab97ab7d290f4a64a5825c876d22109f3bf813254e8601
?
What I know is that ecrecover
returns an address, and verifying a signature is essentially a matter of comparing the resulting address with the expected one. Yet the whole procedure seems unnecessarily complicated.
Aside from this, I was also wondering how I could produce a signature, either like this 0x2ac19db245478a06032e69cdbd2b54e648b78431d0a47bd1fbab18f79f820ba407466e37adbe9e84541cab97ab7d290f4a64a5825c876d22109f3bf813254e8601
or a set of {h, v, r, s}
using Solidity alone, without the RPC-JSON detour as is the case in the question – provided I know a private key?