Signature
Proof of ownership of Externally Owned Accounts (EOAs) is established through private keys and digital signatures.
Last updated
Proof of ownership of Externally Owned Accounts (EOAs) is established through private keys and digital signatures.
Last updated
The first and most crucial step in generating keys is to find a secure source of entropy, or randomness. Generating an Ethereum private key involves selecting a number between 1 and 2ยฒโตโถ.
A private key is a randomly generated 256-bit (32-byte) number.
The public key is set of x and y coordinates on an elliptic curve that satisfy the elliptic curve equation. It is derived from two numbers that are generated from the private key using elliptic curve multiplication. This process is irreversible, meaning that the private key cannot be derived from the public key.
To generate the public key, the private key is used in an equation involving elliptic curve multiplication, which is irreversible. The equation is: K = k * G
, where K is the public key, k is the private key, and G is the constant point (generator point).
Ethereum uses the same elliptic curve, secp256k1
, as Bitcoin.
Ethereum addresses are created by taking the Keccak-256 hash of the public key and representing it as a hexadecimal number. The last 20 bytes of the Keccak-256 hash are used to generate the address.
Example:
Private Key (randomly generated): 0x3a1f59e7b9a7a27b3d905a1f0ce2b1dbdb16ee1e3a78384b6a9f3de75ef1e64a
Public Key (derived from private key): 0x04c7b5ba59e0581ad4f3a195790fda46d4e840da00aeb0eb06802b62c0ad22a1f8d1897bcbb15a4919a242d40d38c48b4fc3a029d270066a3b7ad6cc5c00ee66d9
Ethereum Address (last 20 bytes of public key hash): 0x2e0e4c47e30f71667a9f211bf2e870b6c309ae14
To prove you are the true owner of an EOA, you need to sign a message with the corresponding private key. This means that only you have access to the funds on your account. When making a transaction sending 1 Ether to a contract to mint a new NFT, under the hood, Ethereum verifies the digital signature you created (using the private key) against the corresponding accountโs public key hash (the address).
As we learned, public key cryptography (also known as asymmetric encryption) is a cryptographic method that uses a key pair system. The one key, called the private key, signs the message. The other key, called the public key, verifies the signature. When we sign any message, whether a transaction on Ethereum or any form of data, we create a digital signature. This is done by hashing the message and running the ECDSA algorithm to combine the hash with the private key, producing a signature. By doing this, any changes to the message will result in a different hash value.
As we can read from the Mastering Ethereum book, โA digital signature can be created to sign any message. For Ethereum transactions, the details of the transaction itself are used as the message. The mathematics of cryptography โ in this case, elliptic curve cryptography โ provides a way for the message (i.e., the transaction details) to be combined with the private key to create a code that can only be produced with knowledge of the private key. That code is called the digital signature.โ
Above is another explanation of digital signatures, but in the context of Ethereum transactions. This explanation introduces us to another, very important subject โ elliptic curve cryptography.