Skip to content

Commit caf046d

Browse files
committed
translate blockchain section
1 parent e224263 commit caf046d

File tree

17 files changed

+1375
-3
lines changed

17 files changed

+1375
-3
lines changed

docs/blockchain/bitcoin-basics/cryptocraphy/address.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,95 @@ sidebar_position: 4
33
---
44

55
# Address
6+
7+
Introduction to what Bitcoin and MVC addresses are.
8+
9+
## Address Overview
10+
11+
An address is an identifier for the recipient of a UTXO, used to represent the recipient's identity. Addresses come in
12+
various types based on their form. Some addresses are generated through [public key hashes](public-key-hash.md), some
13+
through script hashes, and others through [public keys](public-key.md). Depending on the situation, the method of
14+
calculating an address may vary.
15+
16+
A Bitcoin address is the unique identifier for a user to receive Bitcoin, akin to a bank account number. They usually
17+
consist of a string of letters and numbers, used for receiving and sending Bitcoin transactions. Essentially, Bitcoin
18+
addresses are generated from public keys, ensuring user privacy and security.
19+
20+
## Address Calculation
21+
22+
The process of generating a Bitcoin address is as follows:
23+
24+
1. **Generate a Private Key**: Use an encryption algorithm (such as elliptic curve encryption) to generate a random
25+
private key.
26+
2. **Generate a Public Key**: Use the Elliptic Curve Digital Signature Algorithm (ECDSA) to generate a public key from
27+
the private key.
28+
3. **Calculate the Address**:
29+
- The public key is hashed using SHA-256 and RIPEMD-160 to obtain the public key hash (Public Key Hash).
30+
- The public key hash is prefixed with a version byte (usually `0x00`, indicating a mainnet address) to get a new
31+
hash value.
32+
- The new hash value undergoes a double SHA-256 hash, and the first 4 bytes are taken as the checksum.
33+
- The checksum is appended to the public key hash to get the final Bitcoin address.
34+
4. **Base58 Encoding**: The resulting Bitcoin address is Base58 encoded to generate the final human-readable Bitcoin
35+
address.
36+
37+
## Address Encoding and Checksum
38+
39+
Bitcoin address encoding uses Base58Check encoding. Base58 is designed to avoid character confusion by removing easily
40+
confused characters (such as 0, O, l, I, etc.). Base58Check encoding consists of two parts:
41+
42+
1. **Base58 Encoding**: Encode the address data using Base58.
43+
2. **Checksum**: Add a 4-byte SHA-256 hash checksum to the end of the address data to ensure its validity.
44+
45+
## Differences Between Mainnet and Testnet Addresses
46+
47+
Bitcoin mainnet and testnet addresses differ in their prefixes:
48+
49+
- **Mainnet Addresses**: Usually start with `1` or `3`, with prefixes `0x00` (P2PKH) or `0x05` (P2SH).
50+
- **Testnet Addresses**: Usually start with `m` or `n`, with prefixes `0x6F` (P2PKH) or `0xC4` (P2SH).
51+
52+
## Main Address Formats
53+
54+
### P2PK (Pay-to-PubKey)
55+
56+
P2PK addresses use the public key directly to receive Bitcoin and are typically not used alone but as a basis for P2PKH.
57+
The P2PK transaction script is:
58+
59+
```
60+
<pubkey> OP_CHECKSIG
61+
```
62+
63+
### P2PKH (Pay-to-PubKeyHash)
64+
65+
P2PKH is the most common address format, generated based on the public key hash. P2PKH addresses usually start with `1`.
66+
The P2PKH transaction script is:
67+
68+
```
69+
OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
70+
```
71+
72+
### P2SH (Pay-to-Script-Hash)
73+
74+
P2SH addresses allow for more complex scripts and conditional payments, generated based on the script hash. P2SH
75+
addresses usually start with `3`. The P2SH transaction script is:
76+
77+
```
78+
OP_HASH160 <scriptHash> OP_EQUAL
79+
```
80+
81+
### P2MS (Pay-to-MultiSig)
82+
83+
P2MS addresses are used for multi-signature payments, requiring multiple private key signatures to unlock Bitcoin. The
84+
P2MS transaction script is:
85+
86+
```
87+
<m> <A_pubKey> <B_pubKey> <C_pubKey> <n> OP_CHECKMULTISIG
88+
```
89+
90+
Where `m` is the minimum number of signatures required, and `n` is the number of public keys.
91+
92+
## Summary
93+
94+
Addresses are a crucial part of the Bitcoin and MVC networks, used to identify transaction recipients. Different types
95+
of addresses suit different use cases, ranging from simple single signatures to complex multi-signature mechanisms.
96+
Understanding the generation, encoding, and verification processes of Bitcoin addresses helps in better comprehending
97+
Bitcoin's security and privacy protection mechanisms.

docs/blockchain/bitcoin-basics/cryptocraphy/base58.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,95 @@ sidebar_position: 8
33
---
44

55
# Base58 Encoding
6+
7+
An introduction to Base58, a user-friendly data encoding method.
8+
9+
```text
10+
alphanumeric = 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
11+
base58 = 123456789ABCDEFGH JKLMN PQRSTUVWXYZabcdefghijk mnopqrstuvwxyz
12+
```
13+
14+
## 1. What is Base58
15+
16+
Base58 is an encoding scheme used to represent large integers, primarily designed to reduce character confusion and
17+
enhance readability. Derived from Base64 encoding, it eliminates easily confused characters like 0 (zero), O, I, and l.
18+
Base58 is particularly useful in Bitcoin and other cryptocurrencies, balancing security and readability.
19+
20+
## 2. The Base58 Encoding Process
21+
22+
The Base58 encoding process involves:
23+
24+
1. **Selecting Character Set**: Base58 uses the characters `123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`.
25+
2. **Data Preparation**: Convert the data (usually a large integer) into a byte array.
26+
3. **Conversion Steps**:
27+
- Treat the byte array as a large integer.
28+
- Repeatedly perform modulo 58 operations on the large integer, converting the remainder to the corresponding Base58
29+
character.
30+
- Continue modulo 58 operations on the quotient until it becomes zero.
31+
4. **Handling Leading Zeros**: Preserve leading zeros in the original byte array as the Base58 character `1`.
32+
5. **Combining Results**: Combine all Base58 characters to form the final encoded string.
33+
34+
### Encoding Example
35+
36+
To encode the integer `100` in Base58:
37+
38+
1. **Data Preparation**: Convert the integer `100` to a byte array `[100]`.
39+
2. **Conversion Steps**:
40+
- Initial value 100, modulo 58 gives remainder 42, corresponding to Base58 character `j`.
41+
- Quotient is 100 // 58 = 1, continue modulo 58 giving remainder 1, corresponding to Base58 character `2`.
42+
- Final quotient is 0, conversion ends.
43+
3. **Handling Leading Zeros**: No leading zeros.
44+
4. **Combining Results**: Combine Base58 characters to get the result `2j`.
45+
46+
## 3. Advantages of Base58
47+
48+
Base58 offers several advantages over other encoding schemes like Base64:
49+
50+
1. **Reduced Character Confusion**: Eliminates confusing characters like `0` and `O`, `I` and `l`, enhancing readability
51+
and user experience.
52+
2. **Improved Input Accuracy**: Users are less likely to make errors when manually entering or copying Base58 encoded
53+
data.
54+
3. **Compactness**: Base58 encoding is more compact compared to hexadecimal representation, reducing the length of
55+
encoded strings.
56+
4. **Cross-Platform Compatibility**: Base58 encoded results only contain numbers and uppercase/lowercase letters, making
57+
it suitable for various platforms and systems, avoiding character set incompatibility issues.
58+
59+
## 4. Applications of Base58 in Bitcoin
60+
61+
Base58 is widely used in Bitcoin and related applications, primarily in the following areas:
62+
63+
### 4.1 Bitcoin Addresses
64+
65+
Bitcoin addresses use Base58Check encoding to ensure readability and integrity. Base58Check adds a checksum to the
66+
Base58 encoding to validate the address and prevent input errors.
67+
68+
The process to generate a Bitcoin address involves:
69+
70+
1. **Generate Public Key Hash**: Using SHA-256 and RIPEMD-160 hash algorithms.
71+
2. **Add Version Prefix**: Prepend the public key hash with a version prefix (e.g., `0x00` for the main network).
72+
3. **Compute Checksum**: Perform double SHA-256 hashing on the data, taking the first 4 bytes as the checksum.
73+
4. **Combine Data**: Concatenate the prefix, public key hash, and checksum.
74+
5. **Base58 Encode**: Encode the combined data using Base58 to produce the Bitcoin address.
75+
76+
### 4.2 WIF Format for Private Keys
77+
78+
Bitcoin private keys use Base58Check encoding in the Wallet Import Format (WIF) to ensure readability and integrity.
79+
80+
The process to generate a WIF private key involves:
81+
82+
1. **Add Version Prefix**: Prepend the private key with a version prefix (e.g., `0x80` for the main network).
83+
2. **Compute Checksum**: Perform double SHA-256 hashing on the data, taking the first 4 bytes as the checksum.
84+
3. **Combine Data**: Concatenate the prefix, private key, and checksum.
85+
4. **Base58 Encode**: Encode the combined data using Base58 to produce the WIF private key.
86+
87+
### 4.3 Transaction ID and Block ID
88+
89+
Bitcoin transactions and blocks use Base58 encoding for their unique identifiers (TxID and BlockID) to ensure they are
90+
easy to read and input.
91+
92+
## Summary
93+
94+
Base58 is an encoding scheme for representing large integers, offering advantages like reduced character confusion,
95+
improved input accuracy, compactness, and cross-platform compatibility. It is widely used in the Bitcoin ecosystem for
96+
Bitcoin addresses, WIF format private keys, and transaction/block identifiers. Understanding Base58 encoding and its
97+
applications helps in better understanding and using Bitcoin and other cryptocurrencies.

docs/blockchain/bitcoin-basics/cryptocraphy/checksum.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,84 @@ sidebar_position: 7
33
---
44

55
# Checksum
6+
7+
Ensuring the integrity and correctness of messages.
8+
9+
## 1. What is a Checksum
10+
11+
A checksum is a technique commonly used in cryptography to verify the integrity and correctness of messages. In Bitcoin,
12+
checksums are used in the generation of addresses and private keys to ensure their validity.
13+
14+
![img.png](/img/bitcoin-checksum.png)
15+
16+
A checksum is a method used to verify data integrity. It generates a fixed-length value by computing part or all of the
17+
data content. During data transmission or storage, the checksum can detect if the data has been tampered with or
18+
corrupted. Checksum technology is widely used in computer networks, data storage, file transfer, and other fields to
19+
ensure data accuracy and integrity.
20+
21+
## 2. Functions of a Checksum
22+
23+
The main functions of a checksum are:
24+
25+
1. **Data Integrity Verification**: During data transmission or storage, checksums can detect if the data has been
26+
accidentally modified or corrupted.
27+
2. **Error Detection**: Checksums can be used to detect errors in data, especially transmission errors.
28+
3. **Data Security**: By verifying the checksum, it ensures that the data has not been tampered with during transmission
29+
or storage, thus improving data security.
30+
31+
## 3. Calculating a Checksum
32+
33+
The process of calculating a checksum usually involves the following steps:
34+
35+
1. **Choose an Algorithm**: Select a suitable checksum algorithm based on the application scenario, such as simple
36+
addition checksum, CRC (Cyclic Redundancy Check), etc.
37+
2. **Calculate the Checksum**: Use the selected algorithm to compute the checksum value of the data.
38+
3. **Append the Checksum**: Attach the calculated checksum to the end of the data or another location for the receiver
39+
to verify.
40+
41+
### Example: Simple Addition Checksum
42+
43+
Assume we have data `[1, 2, 3, 4, 5]` and we want to calculate its checksum using a simple addition method:
44+
45+
1. **Sum the Data**: Add all data elements, resulting in `1 + 2 + 3 + 4 + 5 = 15`.
46+
2. **Modulo Operation**: Perform a modulo operation on the result, e.g., modulo `256`: `15 % 256 = 15`.
47+
3. **Generate Checksum**: The final checksum is `15`.
48+
49+
## 4. Checksum in Bitcoin
50+
51+
Checksums are widely used in Bitcoin to ensure data integrity and security. Here are some key areas where checksums are
52+
used in Bitcoin:
53+
54+
### 4.1 Bitcoin Address Checksum
55+
56+
Bitcoin addresses use Base58Check encoding, which includes a checksum to verify address validity. The steps to generate
57+
a Bitcoin address checksum are:
58+
59+
1. **Generate Public Key Hash**: Using SHA-256 and RIPEMD-160 hash algorithms.
60+
2. **Add Version Prefix**: Prepend the public key hash with a version prefix.
61+
3. **Calculate Checksum**: Perform double SHA-256 hashing on the data and take the first 4 bytes as the checksum.
62+
4. **Combine Address**: Attach the checksum to the public key hash and encode it using Base58 to generate the final
63+
Bitcoin address.
64+
65+
### 4.2 WIF Private Key Checksum
66+
67+
Bitcoin private keys in Wallet Import Format (WIF) also use checksums to ensure key integrity. The steps to calculate a
68+
WIF private key checksum are:
69+
70+
1. **Add Version Prefix**: Prepend the private key with a version prefix.
71+
2. **Calculate Checksum**: Perform double SHA-256 hashing on the data and take the first 4 bytes as the checksum.
72+
3. **Combine Private Key**: Attach the checksum to the private key and encode it using Base58 to generate the WIF
73+
private key.
74+
75+
### 4.3 Block and Transaction Checksums
76+
77+
In the Bitcoin network, each block and transaction includes a checksum to verify data integrity and validity. Checksums
78+
for blocks and transactions are typically calculated using hash functions like SHA-256 to ensure the data has not been
79+
tampered with.
80+
81+
## Summary
82+
83+
Checksums are crucial for verifying data integrity and security. By calculating and verifying checksums, errors and
84+
tampering during data transmission or storage can be detected and prevented. Bitcoin extensively uses checksum
85+
mechanisms to ensure the integrity and security of addresses, private keys, blocks, and transactions. Understanding the
86+
principles and applications of checksums helps in better protecting and managing digital assets.

docs/blockchain/bitcoin-basics/cryptocraphy/hd-wallet-seed.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,121 @@ sidebar_position: 9
33
---
44

55
# HD Wallet and Seed
6+
7+
Introduction to Hierarchical Deterministic Wallets (HD Wallets) and Seeds.
8+
9+
For detailed technical information, please refer
10+
to [BIP-32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki)
11+
12+
![img.png](/img/bitcoin-hd.png)
13+
14+
## 1. Hierarchical Deterministic Wallet (HD Wallet)
15+
16+
The Hierarchical Deterministic Wallet (HD Wallet) is a wallet structure proposed by Bitcoin Improvement Proposal 32 (
17+
BIP-32). An HD wallet generates all private keys and public keys from a single seed, allowing users to manage multiple
18+
addresses with a single backup and offering excellent scalability and security.
19+
20+
## 2. Key Concepts
21+
22+
### 2.1 Seed
23+
24+
The seed is the core of an HD wallet. It is a randomly generated initial value used to generate all key pairs in the
25+
wallet. The seed is typically created by mixing random entropy provided by the user with random numbers generated by the
26+
wallet software.
27+
28+
### 2.2 Mnemonic
29+
30+
A mnemonic is a sequence of easily memorable words that represent the seed. This method not only makes it easier for
31+
users to back up and restore their wallet but also reduces the risk of forgetting or losing the seed. Mnemonics usually
32+
consist of 12, 15, 18, 21, or 24 words selected from a standardized word list.
33+
34+
The steps to generate a mnemonic are as follows:
35+
36+
1. **Generate Random Entropy**: Create random numbers.
37+
2. **Calculate Checksum**: Hash the random numbers using SHA-256 and take the first few bits as the checksum.
38+
3. **Combine Data**: Combine the random numbers with the checksum.
39+
4. **Split Data**: Divide the combined data into 11-bit binary blocks.
40+
5. **Map to Word List**: Map each 11-bit binary block to a word in the standardized word list.
41+
42+
### 2.3 Master Key
43+
44+
The master key is the first key pair generated from the seed, consisting of a master private key and a master public
45+
key. The master key is the starting point of an HD wallet, from which all child keys can be derived.
46+
47+
### 2.4 Child Key
48+
49+
Child keys are derived from the master key or other child keys. HD wallets use a hierarchical structure where multiple
50+
child keys can be derived from a single master key, and each child key can further derive more child keys. The
51+
derivation process is deterministic, meaning the same seed will always generate the same sequence of keys.
52+
53+
### 2.5 Extended Public Key (xpub) and Extended Private Key (xpriv)
54+
55+
Extended public keys (xpub) and extended private keys (xpriv) contain additional information to support the hierarchical
56+
structure of HD wallets.
57+
58+
- **xpub**: Contains the public key, chain code, and derivation path information, allowing the generation of child
59+
public keys without knowing the private key.
60+
- **xpriv**: Contains the private key, chain code, and derivation path information, allowing the generation of child
61+
private keys and child public keys.
62+
63+
### 2.6 Derivation Path
64+
65+
The derivation path is a string that represents the path from the master key to a specific child key. It is usually
66+
written in a slash-separated notation, such as `m/44'/0'/0'/0/0`. Each number represents a level of child key, with `'`
67+
indicating hardened derivation and numbers without `'` indicating non-hardened derivation.
68+
69+
- **m**: Represents the master key.
70+
- **44'**: Indicates adherence to the BIP-44 standard.
71+
- **0'**: Represents the coin type (0 for Bitcoin).
72+
- **0'**: Represents the account.
73+
- **0**: Represents the receiving address.
74+
- **0**: Represents the address index.
75+
76+
## 3. How HD Wallets Work
77+
78+
The operation of HD wallets involves the following steps:
79+
80+
1. **Generate Seed**: The user provides random entropy, and the wallet software generates the seed.
81+
2. **Generate Master Key**: The seed is used to generate the master private key and master public key.
82+
3. **Generate Child Keys**: The master key and chain code are used to generate child keys, which can further generate
83+
more child keys.
84+
4. **Manage Keys and Addresses**: Extended public keys and extended private keys allow the generation and management of
85+
numerous addresses.
86+
87+
## 4. Advantages of HD Wallets
88+
89+
HD wallets have several advantages over traditional wallets:
90+
91+
1. **Simplified Backup**: Users only need to back up the seed or mnemonic once to recover all keys and addresses.
92+
2. **Excellent Scalability**: HD wallets can generate an unlimited number of child keys and addresses, accommodating
93+
various use cases.
94+
3. **Enhanced Security**: Extended public keys do not contain private key information, allowing the generation of child
95+
public keys without exposing private keys.
96+
4. **Standardization**: HD wallets follow standards such as BIP-32, BIP-39, and BIP-44, ensuring compatibility and
97+
interoperability.
98+
99+
## 5. Application Examples
100+
101+
### 5.1 Creating an HD Wallet
102+
103+
1. **Generate Mnemonic**: Generate 12 mnemonic words using random entropy, such
104+
as: `abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about`.
105+
2. **Generate Seed**: Create the seed from the mnemonic.
106+
3. **Generate Master Key**: Use the seed to generate the master private key and master public key.
107+
4. **Generate Child Keys**: Use the master key and chain code to generate child keys, such as the
108+
path `m/44'/0'/0'/0/0`.
109+
110+
### 5.2 Recovering a Wallet
111+
112+
1. **Enter Mnemonic**: The user inputs the backed-up mnemonic.
113+
2. **Generate Seed**: Recover the seed from the mnemonic.
114+
3. **Generate Master Key**: Use the seed to recover the master private key and master public key.
115+
4. **Generate Child Keys**: Use the master key and derivation path to recover child keys and addresses.
116+
117+
## Summary
118+
119+
Hierarchical Deterministic Wallets (HD Wallets) achieve simplified backup, excellent scalability, and enhanced security
120+
through the structured generation and management of seeds, mnemonics, master keys, and child keys. Extended public
121+
keys (xpub) and extended private keys (xpriv), along with derivation paths, have made HD wallets widely used in Bitcoin
122+
and other cryptocurrencies. Understanding the principles and key concepts of HD wallets can help better manage and use
123+
cryptocurrency assets.

0 commit comments

Comments
 (0)