Progress pill
Introduction to Securing Bitcoin Keys

Understanding Bitcoin Keys Generation

Mastering BTC Pay Server

Understanding Bitcoin Keys Generation

  • What is involved in generating Bitcoin keys?
  • Addresses
  • Public Keys
  • Skill Summary
  • Knowledge assessment

What is involved in generating Bitcoin keys?

Bitcoin wallets, when created, create a so-called "seed". In the last objective, you created a "seed", The series of words generated before are also known as mnemonic phrases. The seed is used to derive individual Bitcoin Keys and used to send or receive Bitcoin. Seed phrases should never be shared with third parties or untrusted peers.
The seed generation is performed according to the industry standard known as the "Hierarchical Deterministic" (HD) framework.

Addresses

BTCPay Server is built to generate a new Address. This alleviates the problem of public key or Address reuse. Using the same Public key makes tracking your entire payment history very easy. Thinking of keys as one-time-use vouchers would significantly improve your privacy. We also use Bitcoin Addresses, do not confuse these with Public keys.
An Address gets derived from the Public key through a “hashing algorithm.” Most wallets and transactions, however, will display Addresses rather than those public keys. Addresses are, in general, shorter than public keys and usually begin with a 1, 3, or bc1, whereas public keys begin with 02, 03, or 04.
  • Addresses starting with 1..... are still very common addresses. As mentioned in the chapter, "Creating a new store," these are legacy addresses. This address type is meant for P2PKH transactions. P2Pkh uses Base58 encoding, which makes the address case-sensitive. Its structure is based on the public key with an additional digit as the identifier.
  • Addresses starting with bc1... are slowly moving into the very common addresses. These are known as (native) SegWit Addresses. These offer a better fee structure than the other mentioned Addresses. Native SegWit Addresses use Bech32 encoding and only allow for lowercase letters.
  • Addresses starting with 3... are commonly still used by exchanges for deposit addresses. These addresses are mentioned in the chapter "Creating a new store," wrapped or nested SegWit addresses. However, they could also function as a "Multisig Address". When used as a SegWit address, there are some savings on transaction fees, again, less so than Native SegWit. P2SH Addresses use Base58 encoding. This makes it case Sensitive, like the legacy address.
  • Addresses starting with 2... are Testnet addresses. They are meant to receive testnet bitcoin (tBTC). You should never mix this up and send Bitcoin to these addresses. For development purposes, you can generate a testnet wallet. There are multiple faucets online to get testnet Bitcoin. Never purchase Testnet Bitcoin. Testnet Bitcoin is mined. This might be a reason for a developer to use Regtest instead. This is a playground environment for developers, missing certain network components. Bitcoin is, however, very useful for development purposes.

Public Keys

Public keys are less commonly used in practice today. Over time, Bitcoin users have been replacing them with Addresses instead. They do still exist and still get used occasionally. Public keys are, in general, much longer strings than addresses. Just like with addresses, they start with a specific identifier.
  • First, 02... and 03... are very standard public key identifiers encoded in SEC format. These can be processed and turned into addresses for receiving, used for creating multi-sig addresses, or to verify a signature. Early-day Bitcoin transactions used public keys as part of P2PK transactions.
  • HD wallets, however, use a different structure. xpub..., ypub... or zpub... are called extended public keys, or xpubs. These keys are used to derive many public keys as part of the HD wallet. As your xpub holds the records of your entire history, meaning past and future transactions, never share these with untrusted parties.

Skill Summary

In this section, you learned the following:
  • The differences between addresses and public key data types and the benefits of using addresses over public keys.

Knowledge assessment

Describe the benefit of using fresh addresses for each transaction compared to address reuse or public key methods.