# 地址和钱包

By [luxebeng](https://paragraph.com/@luxebeng) · 2022-09-30

---

Bitcoin
=======

### Introduction

Ownership of bitcoin is established through _digital keys_, _bitcoin addresses_, and _digital signatures_.

Keys come in pairs consisting of a private (secret) key and a public key. Think of the public key as similar to a bank account number and the private key as similar to the secret PIN. In bitcoin, we use public key cryptography to create a key pair that controls access to bitcoin. The key pair consists of a private key and—derived from it—a unique public key. The public key is used to receive funds, and the private key is used to sign transactions to spend the funds.

![](https://storage.googleapis.com/papyrus_images/648201e4dfe332058729e47469489a817ee152d8635801faf9aaeee6412a2024.png)

*   Digital Keys => Wallet
    
*   Digital signatures
    
    The digital signature used to spend funds is also referred to as a _witness_, a term used in cryptography.
    
*   Bitcoin address => Pubic Key
    

### Bitcoin Address

Bitcoin addresses are almost always encoded as “Base58Check”, which uses 58 characters (a Base58 number system) and a checksum to help human readability, avoid ambiguity, and protect against errors in address transcription and entry.

![](https://storage.googleapis.com/papyrus_images/f69e235c420d5dee969b8d0be2572bb6e53f9deae7224c5ba41cad632513afea.png)

### Base58Check

Base58 is a set of lowercase and capital letters and numbers without the four (0, O, l, I). and below is the Base58Check encoding process.

![](https://storage.googleapis.com/papyrus_images/c47210bd547e5f74db1e41368296d2feff61a46969c9a5186e562f95378c243d.png)

### Private Key formats

![](https://storage.googleapis.com/papyrus_images/3e3ec374abf0714a1d2df7152d1848b8d3a8087d2f330cab14655cc4d2f06155.png)

**Example**

    Hex             1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD
    WIF             5J3mBbAH58CpQ3Y5RNJpUKPE62SQ5tfcvU2JpbnkeyhfsYB1Jcn
    Hex-compressed  1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD01
    WIF-compressed  KxFC1jmwwCoACiCAWZ3eXa96mBM6tb3TYzGmf6YwgdGWZgawvrtJ
    

### Public Key formats

![](https://storage.googleapis.com/papyrus_images/ccc7662e6f682d8b645e0d93ddec90244c288e1e07b3b1ceb1f9918d640db13b.png)

**Example**

    Point:
    x = F028892BAD7ED57D2FB57BF33081D5CFCF6F9ED3D3D7F159C2E2FFF579DC341A
    y = 07CF33DA18BD734C600B96A72BBC4749D5141C90EC8AC328AE52DDFE2E505BDB
    Uncompressed:
    K = 04F028892BAD7ED57D2FB57BF33081D5CFCF6F9ED3D3D7F159C2E2FFF579DC341A↵
        07CF33DA18BD734C600B96A72BBC4749D5141C90EC8AC328AE52DDFE2E505BDB
    Compressed:
    K = 03F028892BAD7ED57D2FB57BF33081D5CFCF6F9ED3D3D7F159C2E2FFF579DC341A
    

### **Advanced Keys and Addresses**

*   **Encrypted Private Keys (BIP-38)** BIP-38 proposes a common standard for encrypting private keys with a passphrase and encoding them with Base58Check.
    
*   **Pay-to-Script Hash (P2SH)**
    
    P2SH designate the beneficiary of a bitcoin transaction as the hash of a script, instead of the owner of a public key.
    
*   **Paper Wallets**
    
    Paper wallets are bitcoin private keys printed on paper.
    

Wallet
------

*   A wallet is an application that serves as the primary user interface.
    
*   From a programmer’s perspective, the word “wallet” refers to the data structure used to store and manage a user’s keys.
    

**Wallet Technology Overview**

The wallet contains only keys rather than Bitcoin. In a sense, a bitcoin wallet is a _keychain_.

*   **N_ondeterministic wallet_**
    
    where each key is independently generated from a random number. The keys are not related to each other.
    
*   **D\*eterministic wallet** W\*here all the keys are derived from a single master key, known as the _seed_. All the keys in this type of wallet are related to each other and can be generated again if one has the original seed. The most commonly used derivation method uses a tree-like structure and is known as a _hierarchical deterministic_ or _HD_ wallet.
    
    Deterministic wallets are initialized from a seed. To make these easier to use, seeds are encoded as English words, also known as _mnemonic code words_.
    
*   **HD Wallets (BIP-32/BIP-44)**
    
    HD wallets offer two major advantages over random (nondeterministic) keys. First, the tree structure can be used to express additional organizational meaning; The second advantage is that users can create a sequence of public keys without having access to the corresponding private keys.
    
*   **Seeds and Mnemonic Codes (BIP-39)** HD wallets are useful if they are combined with a standardized way of creating seeds from a sequence of English words.
    

### **Wallet Technology Details**

*   **Mnemonic Code Words (BIP-39)**
    
    how to create mnemonic words
    

![](https://storage.googleapis.com/papyrus_images/553d1107b2c283deceda152d275fc989213bb00c84a0c643d639fb9f1e368552.png)

![](https://storage.googleapis.com/papyrus_images/c0a393f517515c91ed19c6b2a7e89a64fee7c4691a62db6c46299ad1c05e2559.png)

*   **Creating an HD Wallet from the Seed**
    
    Mnemonic code == > Root Seed == > Master Key + Chain code
    
    The process of creating the master keys and master chain code for an HD wallet:
    

![](https://storage.googleapis.com/papyrus_images/1c0077d1fe11088579c061939d72f283ea9624aa2164a6bc1373175841c49db0.png)

*   Extending a parent private key to create a child private key:
    

![](https://storage.googleapis.com/papyrus_images/0d75be9997025cfcd1de3f067796a9aff76f41698b01192f76280a56724500e1.png)

Extended keys: The combination of a private key and chain code is used to derive child private keys; a public key and chain code, which can be used to create child public keys (_public only_);

*   **Using an Extended Public Key on a Web Store**
    

BIP-44 HD wallet structure examples:

![](https://storage.googleapis.com/papyrus_images/408b66ecf21a7d01918961d05ee9b36f3c641bc933a965478ec4fd1130f0a52f.png)

Ethereum
========

### Keys and Addresses

Ethereum has two different types of accounts: _externally owned accounts_ (EOAs) and _contracts_. Ownership of ether by EOAs is established through digital _private keys_, _Ethereum addresses_, and _digital signatures_. In public key cryptography–based systems, such as that used by Ethereum, keys come in pairs consisting of a private (secret) key and a public key.

### **Private Keys**

same as Bitcoin.

### **Public Keys**

Same as Bitcoin.

    k =f8f8a2f43c8376ccb0871305060d7b27b0554d2cc72bccf41b2705608452f315
    K = k * G and K = (x, y)
    where:
       x = 6e145ccef1033dea239875dd00dfb4fee6e3348b84985c92f103444683bae07b
       y = 83b5c38e5e2b0c8529d7fa3f64d46daa1ece2d9ac14cab9477d042c84c32ccd0
    
    Ethereum uses uncompressed public keys; therefore the only prefix is (hex) 04. The serialization concatenates the x and y coordinates of the public key:
       04 + x-coordinate (32 bytes/64 hex) + y-coordinate (32 bytes/64 hex)
    
    Therefore, the public key(K) we calculated earlier is serialized as:
       046e145ccef1033dea239875dd00dfb4fee6e3348b84985c92f103444683bae07b83b5c38e5e2b0c8529d7fa3f64d46daa1ece2d9ac14cab9477d042c84c32ccd0
    

### **Cryptographic Hash Functions**

Ethereum uses the _Keccak-256_ cryptographic hash function in many places. while Bitcoin uses SHA256 here.

### Ethereum Addresses

    We use Keccak-256 to calculate the hash of this public key:
    Keccak256(K) = 2a5bc342ed616b5ba5732269001d3f1ef827552ae1114027bd3ecf1f086ba0f9
    

*   **Ethereum Address Formats**
    

Ethereum addresses are hexadecimal numbers, identifiers derived from the last 20 bytes of the Keccak-256 hash of the public key. Unlike Bitcoin addresses, which are encoded in the user interface of all clients to include a built-in checksum to protect against mistyped addresses, Ethereum addresses are presented as raw hexadecimal without any checksum. In reality, this design choice led to a number of problems in the early days of the ecosystem, including the loss of funds due to mistyped addresses and input validation errors.

*   **Inter Exchange Client Address Protocol**
    
*   **Hex Encoding with Checksum in Capitalization (EIP-55)**
    
        1. address:
            0x001d3F1ef827552Ae1114027BD3ECF1f086bA0E9
        2. hash
            Keccak256("001d3f1ef827552ae1114027bd3ecf1f086ba0e9") =
           5429b5d9460122fb4b11af9cb88b7bb76d8928862e0a57d46dd18dd8e08a6927
        3. Lineup the address and Hash 
            Address: 001d3f1ef827552ae1114027bd3ecf1f086ba0f9
          Hash   : 23a69c1653e4ebbb619b0b2cb8a9bad49892a8b9...
        4. Capitalize each alphabetic address character if the corresponding hex digit of the hash is greater than or equal to 0x8.
            Address: 001d3F1ef827552Ae1114027BD3ECF1f086bA0F9
          Hash   : 23a69c1653e4ebbb619b0b2cb8a9bad49892a8b9...
        
    

Ethereum Wallet
===============

### **Wallet Technology Overview**

the technology is same as Bitcoin.

*   **Nondeterministic (Random) Wallets**
    
*   **Deterministic (Seeded) Wallets**
    
*   **Hierarchical Deterministic Wallets (BIP-32/BIP-44)**
    
*   **Seeds and Mnemonic Codes (BIP-39)**
    

### **Wallet Best Practices**

Same as Bitcoin.

---

*Originally published on [luxebeng](https://paragraph.com/@luxebeng/SuXnx3rwuXwonQw9UQDp)*
