-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<h1 align="center">助记词</h1> | ||
|
||
## BIP32 | ||
|
||
`BIP32`(Bitcoin Improvement Proposal 32)同样是比特币生态系统中的一项重要标准,它提出了“Hierarchical Deterministic | ||
Wallets”(分层确定性钱包,简称HD钱包)的概念。`BIP32` 定义了一种方法,通过一个主私钥(Master Private Key)和相应的主链码(Master | ||
Chain Code)能够派生出无数个子私钥和对应的子公钥。 | ||
|
||
这种机制允许用户从一个单一的种子(`seed` | ||
)生成一棵完整的密钥树,其中每个节点都代表着一个不同的密钥对,并且可以通过一个路径表达式来定位特定的密钥。这样一来,用户可以方便地管理和备份密钥,只需要安全地存储种子或者主私钥即可,而无需单独管理每一个派生出的密钥。 | ||
|
||
`BIP32` 的引入促进了密钥管理的模块化和安全性提升,也为后来的 `BIP39`(助记词生成)、`BIP44`(多币种和多账户结构)等标准提供了基础支持。 | ||
|
||
`BIP32` 流程: | ||
|
||
+ 使用一个熵源(如随机数生成器)生成一个种子(`seed`),通常是`128`位、`192`位、`256`位长的一个字节数组; | ||
+ 将这个种子通过一个称为 `PBKDF2`(Password-Based Key Derivation Function 2)或其他`哈希函数`处理,生成一个派生密钥(`Master | ||
Secret`); | ||
+ 使用 `Master Secret`、一个固定的`标识符`以及一个链码(`chain code`)来构造主扩展密钥(`Master Extended Key` | ||
),它可以是私钥版本(Master Private Key,也称作m)或公钥版本(Master Public Key)。 | ||
|
||
## BIP39 | ||
|
||
BIP39 | ||
主要是为了解决密钥备份和恢复的问题,它提供了一种将随机数生成的密钥种子映射到人类易于记忆的助记词列表(通常为12个、15个、18个或24个单词组成的短语)的方法。这些助记词由特定的单词列表生成,用户可以凭借这些助记词重建丢失的密钥。这种方法大大增强了密钥的可移植性和易用性。 | ||
|
||
## BIP44 | ||
|
||
`BIP44` 是一种密钥层次确定性(Hierarchical | ||
Deterministic,HD)钱包的标准,它规定了如何组织和管理钱包内的密钥和地址结构。`BIP44` | ||
引入了一个树状的密钥层次结构,允许用户从一个单一的种子(例如,`BIP39` 助记词生成的种子)生成无限数量的密钥对。 | ||
|
||
BIP44 规定了密钥路径的层次结构,典型路径格式如下: | ||
|
||
``` | ||
m / purpose' / coin_type' / account' / change / address_index | ||
``` | ||
|
||
+ `m` 是根节点。 | ||
+ `purpose` 通常为 44',表示遵循 BIP44 标准。 | ||
+ `coin_type` 表示支持的加密货币类型,例如比特币为 0'。 | ||
+ `account` 表示用户的钱包账户。 | ||
+ `change` 表示是用于接收(外部链)还是更改(内部链)资金的地址,0 代表外部链,1 代表内部链。 | ||
+ `address_index` 是同一层级内生成的地址索引。 | ||
|
||
> 通过这个结构,用户不仅可以更好地组织密钥,还能在多个设备间同步和恢复钱包状态,同时增加了隐私性和安全性,因为每一个交易只会使用相应路径下的一个新地址。 | ||
## 熵与助记词个数的关系 | ||
|
||
+ 16 byte <sub>128 bits</sub> 的熵会产生 12 个助记词; | ||
+ 20 byte <sub>160 bits</sub> 的熵会产生 15 个助记词; | ||
+ 24 byte <sub>192 bits</sub> 的熵会产生 18 个助记词; | ||
+ 32 byte <sub>256 bits</sub> 的熵会产生 24 个助记词。 |