What is a digital signature?
A digital signature is something you can use to show that you know the private key connected to a public key, without having to reveal the actual private key.
So if anyone ever asks if you have the private key for a specific public key (or address), you can give them a digital signature to prove it.
You just need to do a bit of mathematics to prove that the digital signature is connected to the public key.
Why do we use digital signatures in Bitcoin?
Because when you make a transaction, you need to unlock the outputs you’re trying to use. This is done by showing that you “own” the output, and you do this by showing that you know the private key of the address the output is locked to:
But if you put your private key in to the transaction data, everyone on the network will be able to see it:
And if anyone gets your private key, they can use it to unlock and spend any other outputs that have been locked to that same address.
So how can we unlock outputs without giving our private key away?
Enter the digital signature.
A digital signature can be used to unlock outputs, because it shows that we know the private key of an address.
But the best thing is, using a digital signature means that we don’t give our private key away to the network:
This is why we use digital signatures instead of putting our private keys directly in to the transaction data.
What’s stopping someone from using a digital signature to unlock other outputs at my address?
Good question. After all, if the private key will unlock any output locked to an address, why can’t someone take the digital signature and use it to do the same thing?
Answer: Because every digital signature is unique to that transaction.
In other words; you don’t just use your private key to make a digital signature… you use your private key and the original transaction data itself:
Therefore, each digital signature is tied to the transaction it is being used in:
So if someone tries to use this digital signature in a different transaction, it will conflict with the transaction data in the memory of the digital signature, and nodes on the bitcoin network will not accept it.
As a result, the digital signature will also protect against anyone tampering with the transaction it is being used in.
How do digital signatures work?
Mathematics, my boy.
- You combine the
transaction data, and use some mathematics to create a digital signature.
- You can then take the digital signature +
public key, do some more mathematics with them, and the result will confirm whether a legitimate private key was used to create the digital signature.
Because remember, the goal of a digital signature is to prove that you’re the owner of a public key.