title: Keys, Addresses theme: sjaakvandenberg/cleaver-light
Keys, Addresses
Bitcoin Addresses
- There are currently two address formats in common use:
- Common P2PKH(Pay-to-Public-Key-Hash) which begin with the number 1, eg: 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2
- Newer P2SH(Pay-to-Script-Hash) type starting with the number 3, eg: 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy
Public key to bitcoin address
- Starting with the public key K, we compute the SHA256 (Secure Hash Algorithm) hash and then compute the RIPEMD160 (RACE Integrity Primitives Evaluation Message Digest) hash of the result, producing a 160-bit (20-byte) number: A = RIPEMD160(SHA256(K))
Base58 and Base58Check Encoding
- A modified Base 58 binary-to-text encoding known as Base58Check is used for encoding Bitcoin addresses.
- Base58 is Base64 without the 0 (number zero), O (capital o), l (lower L), I (capital i), and the symbols “+” and “/”.
- The result is composed of three items: a single version byte prefix, the hash, and a checksum(only the first 4 bytes).
- checksum = SHA256(SHA256(version+hash))
Version bytes
Type | Version prefix (hex) | Base58 result prefix |
---|---|---|
Bitcoin Address | 0x00 | 1 |
Pay-to-Script-Hash Address | 0x05 | 3 |
Namecoin pubkey hash | 0x34 | M or N |
Bitcoin Testnet Address | 0x6F | m or n |
Private Key WIF | 0x80 | 5, K, or L |
BIP-38 Encrypted Private Key | 0x0142 | 6P |
BIP-32 Extended Public Key | 0x0488B21E | xpub |
Source code
- https://github.com/bitcoin/bitcoin/blob/master/src/base58.h
- https://github.com/bitcoin/bitcoin/blob/master/src/base58.cpp