For bitcoin users, they are most directly related to the private key, account and wallet in Bitcoin. Here are three concepts and related details. Before that, a brief description of public key cryptography knowledge.

Public-key Cryptography

Public key cryptosystem is divided into three parts: public key, private key, encryption and decryption algorithm. Both the public key and the algorithm of a public key cryptosystem are public (hence the name of the public key cryptosystem), and the private key is secret. For different purposes, you can use the public key or private key for encryption, and then use the corresponding private key or public key for decryption. The public key cryptosystem has the following functions:

  • Encryption and decryption function
  • Signature verification function
  • Key negotiation function

In the Bitcoin system, we use public key encryption to create a key pair that controls the acquisition of bitcoins. A key pair consists of a private key and a unique public key derived from it. The public key is used to receive bitcoin, while the private key is used to sign transactions when bitcoin is paid. The mathematical relationship between the public and private keys that allows the private key to be used to generate a signature for a particular message. This signature validates the public key without disclosing the private key. To pay for bitcoin, the current owner of the bitcoin submits its public key and signature in the transaction (the signature is different for each transaction, but is generated from the same private key). Everyone in the Bitcoin network can verify with the submitted public key and signature, and confirm whether the transaction is valid, that is, confirm that the payer has ownership of the bitcoin being traded at that moment.

The private key

The private key is just a random number. Control of all funds in a Bitcoin address depends on ownership and control of the corresponding private key. In bitcoin transactions, the private key is used to generate the signatures necessary to pay bitcoin to prove ownership of the funds. The private key must always be kept secret, because if it is leaked to a third party, the bitcoin protected by the private key is in effect given away. The private key must also be backed up in case it is accidentally lost, because once lost, the private key is difficult to recover and the bitcoin it protects is lost forever.

How did you pick this random number? This is generally done through random function generators, which will not be covered here.

Bitcoin account

In the figure above, we have seen the general generation process of the Bitcoin account (address) (private key –> public key –> Bitcoin address), which is described in detail here. Two cryptographic hash functions, SHA256 and RIPEMD160, are applied in the process of bitcoin account generation. The following figure shows the generation process of bitcoin address (account) :

  1. Generate a 256bit random number through the random number generator and use the random number as the private key of the account.
  2. Bitcoin uses the Elliptic Curve Signature algorithm (ECDSA) to sign and verify data, using the SECP256K1 curve. The corresponding public key can be calculated by ECC multiplication.
  3. Hash the public key twice to get the hash value of the public key.
  4. right< COINS address prefix 0 x00 | public key hash value >Do a double hash, taking the first 4 bytes as the check code.
  5. right< COINS address prefix 0 x00 hash | | the public key check code >Base58 encoding to get the address.

The meanings of other prefixes are as follows:

species Version prefix (HEX) Base58 format
Bitcoin Address 0x00 1
Pay-to-Script-Hash Address 0x05 3
Bitcoin Testnet Address 0x6F m or n
Private Key WIF (Wallet import format) 0x80 5 (no compression), K or L (compressed format)
BIP38 Encrypted Private Key 0x0142 6P
BIP32 Extended Public Key 0x0488B21E xpub

Base58 encoding is used to encode the address, mainly for the convenience of use and identification.

Bitcoin wallet

Wallet is an application that provides an interactive interface for the user. Wallets control user access, manage keys and addresses, track balances, and create and sign transactions. Among them, the most core function is to keep the private key, once the private key is leaked or forgotten, it will cause bitcoin to be stolen or lost.

Is there any Bitcoin in the wallet? The wallet only contained the key, not bitcoin.

So where’s my bitcoin? The bitcoin you own is essentially the output of all your account addresses for unspent transactions. The wallet will monitor the output to your public key address. For example, if A transfers 1 bitcoins to you and B transfers 9 bitcoins to you, and you are not transferring them to anyone else, the wallet calculates that you currently have 10 bitcoins. When you take the currency transfer to other people, you construct a deal, trade your not spend for output as input, the output for the receiver address, account and set up the transfer amount, your public key information, etc, to sign again trading (private key signature) confirmed, send to the currency network waiting for confirmation, the transfer is complete.

Welcome to pay attention to wechat public number, learn blockchain related technology together!