本文是比特币钱包的创建流程。
1 创建钱包流程

2 种子生成过程
种子生成过程: hdkeychain.GenerateSeed
func GenerateSeed(length uint8) ([]byte, error) {
// Per [BIP32], the seed must be in range [MinSeedBytes, MaxSeedBytes].
if length < MinSeedBytes || length > MaxSeedBytes {
return nil, ErrInvalidSeedLen
}
buf := make([]byte, length)
_, err := rand.Read(buf)
if err != nil {
return nil, err
}
return buf, nil
}
其核心就是rand.Read,就是生成一个256bit的随机数。
3 生成钱包 CreateNewWallet:

4 总结
本文讲解了钱包创建流程。将种子生成过程、钱包生成过程单独讲了一下。
5 参考文献
btcwallet 源码。
6 其他
本文是《循序渐进比特币》的第七篇-《btcwallet(一) 钱包创建》。
如果有疑问,可以直接留言,也可以关注公众号 “链人成长chainerup” 提问留言,或者加入知识星球“链人成长”~
网友评论