2021-05-13
Explanation of the private key, public key and address of the digital currency wallet
Wallet is an application that provides a user interface. It controls user access rights, manages keys and addresses, tracks balances, and creates and signs transactions. From a technical point of view, "wallet" refers to a data structure used to store and manage user keys. Transaction information is recorded in the blockchain, and users control the digital currency on the network by signing transactions with the keys in their wallets. This chapter uses Bitcoin as an example to introduce various technical mechanisms in
digital currency wallets.
Private key, public key and address
In Bitcoin, three words often appear: private key, public key, and address, and they are often mentioned together. A Bitcoin wallet contains a series of key pairs, and each key pair includes a private key and a public key. The private key is a number, usually selected at random. With the private key, we can use the one-way encryption function of elliptic curve multiplication to generate a public key. With the public key, we can use a one-way cryptographic hash function to generate a Bitcoin address.
Through the applicability of asymmetric cryptography, anyone can verify each signature of each transaction, while ensuring that only the owner of the private key can generate a valid signature.
Private key
The private key is the representative who has the right to withdraw money to a bitcoin address. If you master the private key, you have the right to control the bitcoin on the corresponding address. The private key can be used to calculate the public key, and the public key can be used to calculate the Bitcoin address. In each transaction, the payer must issue a private key and a signature generated by the private key. The signature of each transaction is different, but it is generated by the same private key. Usually the private key we see is the following string of characters:
Applications that support the Bitcoin protocol can correctly convert this string into a Bitcoin private key, then convert the public key, and then get an address. If the address has a corresponding Bitcoin on it, you can use this private key to spend Bitcoin above.
The private key is essentially a random number, an array composed of 32 bytes, 1 byte is equal to 8 bits of binary, and a binary has only two values, 0 or 1. Therefore, the total number of private keys is close to 2,256, which has exceeded the total number of atoms in the universe. It is impossible to traverse all the private keys and exhaust the energy of the entire sun. The security of the private key is guaranteed by mathematics. If you want to break it through technical means, you may have to wait for the maturity of quantum computer technology.
Public key
The public key can be calculated from the private key by elliptic curve multiplication. This is an irreversible process: K = k * G. Where k is the private key, G is the constant point called the generating point, and K is the resulting public key. The reverse operation is called "finding the discrete logarithm"-knowing the public key K to find the private key k-is very difficult, just like experimenting with all possible values of k, that is, brute force search. Therefore, the owner of the private key can easily create a public key and then share it with the world, knowing that no one can reverse the function from the public key and calculate the private key. This mathematical technique becomes the basis for an unforgeable and secure digital signature that proves the ownership of Bitcoin funds.
The public key is used to verify the signature of the private key. Generally, we rarely see the public key. After signing the transaction with the private key, we will send our public key together with the transaction, so that for a complete transaction, he Just use the public key included in the transaction to verify that the signature of the private key is correct.
address
A Bitcoin address is a string of numbers and letters that can be shared with anyone who wants to give you Bitcoin. In transactions, the Bitcoin address usually appears as the payee. If you compare a Bitcoin transaction to a check, the Bitcoin address is the payee, which is what we want to write in the payee column. The check does not need to specify a specific account, but uses an abstract name as the payee, which makes it a very flexible payment tool. Similarly, Bitcoin addresses use a similar abstraction, which also makes Bitcoin transactions very flexible.
The address generation process is roughly as shown in the figure above. As far as Bitcoin is concerned, a private key can correspond to multiple Bitcoin addresses. Usually we use wallet to transfer money from one address to another address, or scan the QR code, like EOS is the mutual transfer between accounts.