Skip to content
CryptoAcademy logo CryptoAcademy
Menu
Blockchain Article · 10 min read

Digital Signatures in Blockchain: Keys Explained

A Admin
Digital Signatures in Blockchain: Keys Explained

How do digital signatures prove you own your crypto? Learn private and public keys, ECDSA on secp256k1, Schnorr, and see working code you can run.

Digital signatures in blockchain are the reason a network of strangers can agree that a transaction really came from the person who owns the coins. There is no bank, no password reset and no customer service desk checking your ID. Instead, a piece of mathematics lets you prove, in public, that you hold a secret without ever revealing it. In this guide you will learn how private and public keys relate, how a signature is created and checked, why Bitcoin and Ethereum chose the secp256k1 curve, what can go wrong, and how Schnorr signatures improve the picture. There is working code too.

Key takeaways

  • A private key is a secret number. A public key is derived from it with one-way mathematics. Anyone can know the public key; only you should know the private one.
  • A digital signature proves two things at once: the message was approved by the holder of the private key, and it was not changed afterwards.
  • Bitcoin and Ethereum both sign transactions with ECDSA on the secp256k1 curve, and Bitcoin's Taproot upgrade added Schnorr signatures on the same curve.
  • The signing step needs a fresh, unpredictable random number (a nonce). Reusing or leaking it can expose the private key.
  • Your coins are not "inside" your wallet. Whoever controls the private key controls the funds, so key safety is everything.

Why blockchains need digital signatures

Why blockchains need digital signatures

On a blockchain, thousands of independent computers keep the same ledger. When someone says "move 0.5 coins from my address to Bob's", every node must be able to check that the request is genuine, without trusting the sender or any middleman. A handwritten signature cannot do that, because it can be copied. A digital signature can, because it is tied mathematically to both the signer's secret and the exact content of the message.

Three properties matter:

  • Authentication: the signature could only have been produced by the holder of the private key.
  • Integrity: if even one bit of the message changes, the signature no longer verifies.
  • Non-repudiation: the signer cannot later claim they never approved it, since nobody else could have made that signature.

If you want the bigger picture of what happens to a signed transaction next, read our walkthrough of blockchain transactions from wallet to confirmation. For the cryptographic building blocks around this topic, our cryptography fundamentals guide is a good companion.

Private keys and public keys: a one-way relationship

Private keys and public keys: a one-way relationship

Public-key cryptography uses a pair of linked keys:

  • The private key is a secret. On secp256k1 it is simply a 256-bit number. It is chosen at random from the range 1 to n − 1, where n is the order of the curve.
  • The public key is computed from the private key by multiplying a fixed starting point on the curve, called the generator G, by that number.

Going from the private key to the public key is quick. Going backwards is the elliptic curve discrete logarithm problem, for which no efficient algorithm is known. That one-way street is the whole foundation: you can publish the public key, and nobody can work out your private key from it.

Ethereum's documentation states the practical consequence directly: you cannot derive a private key from a public key. It also describes the address as the last 20 bytes of the Keccak-256 hash of the public key, prefixed with 0x, which gives the familiar 42-character address.

private key  --(elliptic curve multiplication, easy)-->  public key
public key   --(discrete log problem, infeasible)-->     private key
public key   --(hash, easy)-->                           address

This is also why wallets matter so much. A wallet is mostly a tool that stores and uses your keys. If you want the details of seed phrases and key storage, see how crypto wallets work.

What is secp256k1?

secp256k1 is the elliptic curve used by both Bitcoin and Ethereum. According to the Bitcoin wiki, it is defined by the equation y² = x³ + 7 over a prime field. It is one of the curves recommended by the Standards for Efficient Cryptography Group (SECG). The Bitcoin wiki notes two reasons it is attractive: its structure allows fast computation, often more than 30% faster than other curves when well optimised, and its constants were chosen in a predictable way, unlike some NIST curves, which lowers the worry about hidden backdoors.

How an ECDSA signature works

How an ECDSA signature works

ECDSA, the Elliptic Curve Digital Signature Algorithm, is the scheme Bitcoin originally used and Ethereum uses for transaction signatures. At a high level:

  1. Hash the message. The transaction data is run through a hash function to produce a fixed-size digest, called e below.
  2. Pick a random nonce k. This single-use secret is fresh for every signature.
  3. Compute the signature (r, s). r comes from the point k·G. The second number is s = k⁻¹(e + r·d) mod n, where d is the private key.
  4. Verify. Anyone with the public key, the message and (r, s) recomputes a curve point and checks that it matches r. If it does, the signature is valid.

A signature is therefore a pair of integers, which is why Ethereum transaction signatures show up as the fields r, s and a recovery value v (or yParity on newer transaction types). Ethereum's accounts documentation also notes that the public key can be derived from a signature, so anyone can check who signed it.

Signing and verifying in Python

This example uses the widely used cryptography package with the same secp256k1 curve that Bitcoin and Ethereum use. It is a teaching example; real wallets add many protections around key storage.

from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature
from cryptography.exceptions import InvalidSignature

private_key = ec.generate_private_key(ec.SECP256K1())
public_key = private_key.public_key()

message = b"Alice pays Bob 0.5 coins"
signature = private_key.sign(message, ec.ECDSA(hashes.SHA256()))
r, s = decode_dss_signature(signature)
print("r =", hex(r)[:18], "...")
print("s =", hex(s)[:18], "...")

try:
    public_key.verify(signature, message, ec.ECDSA(hashes.SHA256()))
    print("valid signature")
except InvalidSignature:
    print("invalid")

try:
    public_key.verify(signature, b"Alice pays Bob 5 coins", ec.ECDSA(hashes.SHA256()))
except InvalidSignature:
    print("tampered message rejected")

Changing "0.5" to "5" in the message makes verification fail, which is exactly the integrity guarantee blockchains rely on.

The same idea in Node.js

Node's built-in crypto module also supports secp256k1:

const { generateKeyPairSync, sign, verify } = require("crypto");

const { privateKey, publicKey } = generateKeyPairSync("ec", { namedCurve: "secp256k1" });
const message = Buffer.from("Alice pays Bob 0.5 coins");

const signature = sign("sha256", message, privateKey);
console.log("valid:", verify("sha256", message, publicKey, signature));
console.log("tampered:", verify("sha256", Buffer.from("Alice pays Bob 5 coins"), publicKey, signature));

Running this prints valid: true followed by tampered: false. Note that Bitcoin and Ethereum apply their own transaction serialisation and hashing before signing (Ethereum, for instance, uses Keccak-256 and RLP encoding), so this snippet shows the principle rather than a real transaction.

From signature to blockchain transaction

From signature to blockchain transaction

When you press "send" in a wallet, this happens, in simplified form:

  1. The wallet builds the transaction: recipient, amount, fee and other fields.
  2. It signs the transaction with your private key. Ethereum's documentation says the transaction object "needs to be signed using the sender's private key" and that client software does the signing.
  3. The signed transaction is broadcast to the network.
  4. Each node checks the signature against the public key (or address) and checks that the sender actually has the funds.
  5. Valid transactions wait to be included in a block by the network's consensus process, which is covered in our article on proof of stake and Ethereum.

Your private key never leaves your device in this process. Only the signature travels, and the signature alone is not enough to sign anything else.

What can go wrong: nonces, malleability and lost keys

What can go wrong: nonces, malleability and lost keys

The mathematics is strong, but the implementation has sharp edges.

Nonce reuse. The random value k must be unpredictable and used only once. Cryptography references on ECDSA explain that if the same nonce is used to sign two different messages, the private key can be calculated from the two signatures. This has caused real losses: a flaw in the random number generator of some Android devices in 2013 led to duplicate nonces in some Bitcoin wallets. Modern libraries mitigate this with deterministic nonce generation (RFC 6979) and good randomness sources, which is one more reason not to write your own cryptography.

Signature malleability. If (r, s) is a valid ECDSA signature, then (r, n − s) is also valid for the same message. Bitcoin therefore applies a "low-S" rule that accepts only one canonical form, so a third party cannot tweak a signature to change a transaction's identifier.

Lost or stolen keys. There is no recovery desk. Lose the private key (or the seed phrase that generates it) and the funds are unreachable; leak it and someone else can sign as you. Never paste a seed phrase into a website, and never share a private key.

Blind signing. A valid signature on a harmful transaction is still valid. Hardware wallets and clear transaction previews exist so you can see what you are approving before you sign.

Beyond ECDSA: Schnorr signatures and Taproot

Beyond ECDSA: Schnorr signatures and Taproot

Bitcoin's Taproot upgrade introduced Schnorr signatures, specified in BIP 340 ("Schnorr Signatures for secp256k1", status: Deployed). They use the same curve, so existing key generation still works, but offer several improvements according to the BIP:

  • Fixed 64-byte signatures and 32-byte public keys, instead of variable-length encodings.
  • Non-malleability: third parties cannot turn a valid signature into another valid one.
  • Provable security under stated assumptions.
  • Batch verification: many signatures can be checked together faster.
  • Linearity: cooperating signers can combine their keys and produce a single signature, which is the basis for efficient multi-signature and threshold schemes.

Ethereum keeps ECDSA for ordinary account transactions. Its validators, however, use a different scheme: BLS keys, which Ethereum's documentation says are used to identify validators. BLS signatures are popular in proof-of-stake systems because many signatures can be aggregated.

If you want to go deeper into the underlying toolkit, our Understanding Cryptography course covers hashing, keys and signatures step by step.

Practical key-safety checklist

Practical key-safety checklist

  • Use a hardware wallet for meaningful amounts, and buy it from the manufacturer.
  • Write your seed phrase on paper or metal, store copies in separate safe places, and never photograph it or store it in cloud notes.
  • Treat every message asking for your seed phrase as a scam.
  • Read what you sign. If a prompt is unclear, reject it.
  • Use well-reviewed libraries and wallets instead of home-made cryptography.
  • Test with a small amount first when trying a new tool or address.

Frequently asked questions

What is the difference between a private key and a seed phrase? A seed phrase is a human-readable backup from which a wallet can generate many private keys. Whoever has the seed phrase can regenerate all the keys derived from it, so it deserves the same protection as the keys.

Can someone steal my crypto if they know my public key or address? Knowing the public key or address does not let anyone spend your funds. Spending requires a valid signature, which requires the private key. Ethereum's documentation states that a private key cannot be derived from public keys.

Is a digital signature the same as encryption? No. Encryption hides content; a signature proves who approved it and that it was not altered. Blockchain transactions are normally public and signed, not encrypted.

Why do Bitcoin and Ethereum use the same curve? Both use secp256k1. The Bitcoin wiki points to its efficiency and its predictably chosen constants. Ethereum adopted the same curve and ECDSA for account signatures.

Will quantum computers break these signatures? Researchers have studied the threat, and migration ideas are discussed in the community, but no widely deployed replacement exists for these chains today. Watch for developments rather than panic.

Conclusion

Digital signatures in blockchain turn a simple idea into a global system: you keep a secret number, publish the matching public key, and sign every action in a way anyone can verify but nobody can forge. The strength comes from one-way mathematics on the secp256k1 curve; the weak points are human ones, such as poor randomness, careless signing and lost keys. Understand the keys, protect the seed phrase, and you understand the core of crypto ownership.

For your next step, try the hands-on exercises in our Interactive Lab, or revisit how Bitcoin works from digital money to blockchain.

Sources

  1. Bitcoin Wiki, "Secp256k1" - https://en.bitcoin.it/wiki/Secp256k1
  2. Ethereum.org, "Ethereum accounts" - https://ethereum.org/en/developers/docs/accounts/
  3. Ethereum.org, "Transactions" - https://ethereum.org/en/developers/docs/transactions/
  4. Bitcoin BIPs, "BIP 340: Schnorr Signatures for secp256k1" - https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
  5. Alin Tomescu, "ECDSA signatures (and why you should avoid them)" - https://alinush.github.io/ecdsa
  6. Python cryptography library documentation (elliptic curve signatures) and Node.js crypto documentation, for the code examples.

Related articles

Comments (0)

Never shown publicly.

Share this page

Send this link to a friend, or scan the QR code to open it on your phone.