A signature is cryptographic proof that a message was approved by a specific wallet (Ethereum address) without revealing the private key.
Ethereum signs a special version of the message with a prefix to prevent misuse:
"\x19Ethereum Signed Message:\n" + message.length + message
A typical Ethereum signature is 132 hex characters and contains 3 parts:
r: 32 bytess: 32 bytesv: 1 byte (27 or 28)// Signing
const signature = await ethereum.request({
method: 'personal_sign',
params: [message, userAddress],
});
// Verifying
const recoveredAddress = ethers.utils.verifyMessage(message, signature);
Ethereum uses the Elliptic Curve Digital Signature Algorithm (ECDSA) over the secp256k1 curve to sign messages. The process involves creating a unique mathematical proof that only the holder of the private key can generate.
K = k ร Gr(x, y) = r ร GR = x mod n (R is part of the signature)s = (z + R ร k) / r mod n(R, s) plus recovery id v (27 or 28)s ร r ร G = z ร G + R ร K
This checks if the signature is consistent with the public key and the hashed message.
keccak256 hashing algorithm (not SHA256)\x19Ethereum Signed Message:\n + length + messagev is used to recover the public key (hence, no need to send public key)| Symbol | Meaning | Details |
|---|---|---|
k |
Private Key | A secret 256-bit number known only to the wallet owner. Used to generate the public key and signature. |
K |
Public Key | Derived from k ร G. Anyone can compute it if they know k. Publicly visible. |
G |
Generator Point | A fixed base point on the secp256k1 elliptic curve. Defined by the curveโs standard. |
r |
Random Nonce | A random number generated during signing. Must be unique and secret for every signature. |
(x, y) |
Point on Curve | Result of multiplying r ร G. Used to compute R = x mod n. |
R |
First Part of Signature | Equal to the x-coordinate of the point r ร G, reduced modulo the curve order. |
z |
Message Hash | The keccak256 hash of the signed message (with Ethereum prefix). |
s |
Second Part of Signature | Computed as s = (z + R ร k) / r mod n. Must be less than curve order / 2 for canonical form. |
v |
Recovery ID | A small number (27 or 28) that helps recover the public key from the signature and the message hash. |
n |
Curve Order | The total number of valid points on the curve. Used for modulo operations. |
| Symbol | Name | Value | Notes |
|---|---|---|---|
p |
Prime Field (modulo) | 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F |
The prime over which the curve is defined (secp256k1 field size) |
n |
Curve Order | 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 |
Total number of valid points (mod n used in sig math) |
G |
Generator Point |
x = 55066263022277343669578718895168534326250603453777594175500187360389116729240 y = 32670510020758816978083085130507043184471273380659243275938904335757337482424 |
Base point used in all key generation |
k |
Private Key (example) | 0x1c3a6c...f8a3b2 (256-bit random) |
Must be a number between 1 and nโ1 |
K |
Public Key | Uncompressed: 0x04 + x + y Compressed: 0x02/03 + x |
Derived from K = k ร G |
z |
Message Hash | keccak256("\x19Ethereum Signed Message:\n" + len + msg) |
Used as input to signature equation |
v |
Recovery ID | 27 or 28 (sometimes 0 or 1) |
Helps recover public key from signature |
r |
Signature Component | 32-byte integer | X-coordinate of r ร G mod n |
s |
Signature Component | 32-byte integer | Signature solution derived from private key |