(这部分基本是翻译自BIP39的wiki,具体地址见参考文献)
BIP39 就是为了解决seed不好记忆的问题诞生的。其最终目标也是生成seed, 不过要先生成助记词,然后再有助记词生成seed 。下面我们看一下两步:
(this part is basically translated from BIP39's wiki, the address of which is the reference)
BIP39 was born to solve the problem of the bad memory of the Seed. The ultimate goal is also to generate the Seed, but Mr. is required to enter the notes and then to use the notes to generate the Seed. Here's two steps:
1.1.1 生成助记词
原理很简单,先有一个128~256位的熵,然后生成校验码 checknum , 然后将校验码添加到熵后面,形成一个拼接的字符串,接下来一步是每11位分隔一下,每个11位会对应一个单词(有一个单词列表)。这些单词最终就组成了助记词。
The principle is simple: first there is a 128 - 256-bit entropy, then there is a checknum, then the checksum is added to the entropy, forming a collusive string, and the next step is to separate every 11, and each 11 will correspond to a word (there is a list of words).
图片来自 《精通比特币》
助记词的单词列表的几个特点:
(1)去除了易混的单词,比如build 跟built 。
(2)经过了排序,方便后续使用trie前缀树进行压缩。
Several features of the list of words to support the word:
(1) removes the easier words, such as buld and bult.
(2) is sorted to facilitate subsequent compression using the tree prefix.
1.1.2 由助记词生成seed
利用助记词 + salt ("mnemonic"+ 可选的密码短语) ,使用HMAC-SHA512 算法,使用2048次哈希来延伸助记词和salt 参数,产生一个512位的种子。
Using the word + salt ("mnemonic"+optional passphrase), using the HMAC-SHA512 algorithm, 2048 Hash extensions the word and salt parameters to produce a 512-bit torrent.
图片来自 《精通比特币》
可选的密码短语,使得助记词不能单独使用,避免助记词被盗后被利用。
The choice of password phrases prevents the use of assistive words on their own and avoids their use when stolen.
1.2.1 子密钥的产生
私有子密钥的产生:母密钥 + 链码 + 索引结合并散列可以生成子密钥。结果是512位的散列,右半部分是256位的链码,左半部分是子密钥。
Private sub-key generation: The parent key + chain code + index combines and hash to generate a sub-key. The result is a 512-bit hash, a 256-digit chain code for the right half, and a sub-key for the left half.
1.2.2 扩展密钥
密钥以及链码被结合之后,就叫扩展密钥。
扩展密钥 + 索引,就可以导出子密钥。
When the key and the chain code are combined, they are called Extended Keys.
The Extended Key + Index allows you to export subkeys.
1.2.3 强化子密钥
因为扩展公钥包含链码,如果子密钥被知道或者被泄露,链码就可以用来衍生其他所有的子私钥。非常危险。为了应对这种风险,HD钱包使用了一种叫做强化衍生的替代衍生函数,打破了母公钥以及子私钥之间的关系。这个硬化函数使用了母私钥去推到子链码,而不能采用母公钥去推到链码。
Because the extended public key contains a chain code, which can be used to derive all other private keys if the subkey is known or leaked. Very dangerous. To address this risk, the HD wallet uses an alternative derivative called enhanced derivative, breaking the relationship between the parent and the sub-key. The hardening function uses the parent private key to push to the sub-chain code, not the parent key to push to the chain number.
1.2.4 HD钱包识别符(密钥路径)
由主私钥衍生出的私钥起始以”m“打头,由主公钥衍生出的公钥以"M"打头。比如m/x/y 是m/x 的第y个子密钥。
Private keys derived from the main private key start with " m" and "M" with the public key derived from the main public key. For example, m/x/y is the yth subkey of m/x.
BIP43 是对BIP32的一种支持,其目的是为了大家生成的密钥路径都遵循相同的规范,其产物还是密钥。
BIP43 is a support for BIP32, the purpose of which is that all key paths generated follow the same specifications, and that the product is the key .
不同人员开发的钱包可能会有不同的规定方式,这就导致了同一种路径可能有多个解释。为了避免混乱,BIP43中将第一层级的编号定义为“目的域”,不同的协议使用不同的编号。比如如果一个钱包结构满足BIP44,它的秘钥路径就应该是m/44’/*这样我们就知道对这个路径的理解方式应该按照BIP44里的规定。
In order to avoid confusion, BIP43 defines the number of the first tier as the “end area” and different protocols use different numbers . For example, if a wallet structure meets BIP44, its key path should be m/44’/* so that we know that this path should be understood in a way that is consistent with BIP44.
BIP43中还规定了在一个数字后加撇号表示这是一个加固子秘钥,也就是说其真实的生成编号为i+2^31 ,比如上文中的44’,其真实对应的生成编号为2^31 +44,即0x8000002C。
Also specified in BIP44在BIP43基础上,提出了多账户结构。其产物还是密钥。 BIP44 presents a multi-account structure based on BIP43. BIP44的五层结构: Five layers of BIP44: 其中每部分的含义是: Each of these parts means: 解锁 Unlock 解锁过程就是利用timeout 构造一个定时器,然后利用这个定时器创建了一个 unlockRequests, 然后向启动时定义的walletLocker routine 中发送unlockRequests 。 The locking process is to construct a timer using timeout, then use this timer to create an unlockRequests, and then send unlockRequests to the walletlocker rootine defined at startup. The 创建账户 Create Account btcwallet 创建的账户是 BIP44类型的账户。 The account created by btcwallet is a BIP44-type account. 本文讲解了BIP39, BIP32,BIP43,BIP44基础协议,然后从源码角度分析了账户创建跟地址创建的流程。 This paper describes the BIP39, BIP32, BIP43, BIP44 basic protocols, and then analyses the process of account creation from a source-code perspective and the creation of addresses. BIP32 BIP44 https://www.cnblogs.com/bytom/p/10410568.html 本文是《循序渐进比特币》的第九篇-《btcwallet(三) 账户创建与地址创建》。 This is the ninth issue of Stepwise Bitcoin -- btcwallet(iii) Account Creation and Address Creation.
walletLocker 的routine来处理这个解锁逻辑。
walletLocker rootine handles this unlocking logic.
如果按照BIP44的定义,生成账户的这一步应该是实现到了BIP44里面的 account 这一级。
If, as defined in BIP44, this step in generating an account should have reached the level of account in BIP44.
BIP39 助记词相关bitcorn 官方wiki https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
《精通比特币》第二版
BIP32 翻译 https://blog.csdn.net/pony_maggie/article/details/76178228
HD钱包 bip43 bip44 https://www.linksfin.com/article/244279
如果有疑问,可以直接留言,也可以关注公众号 “链人成长chainerup” 提问留言,或者加入知识星球“链人成长”~
If you have any questions, you can leave a direct message, or you can focus on the public number “Chainerup” asking questions, or joining the knowledge planet “Chainerup” ~
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论