shownb / shownb.github.com

shownb.github.io
shownb.github.io
5 stars 1 forks source link

hd wallet #26

Open shownb opened 5 years ago

shownb commented 5 years ago

图片

BIP39:将 seed 用方便记忆和书写的单字表示。一般由 12 个单字组成,称为 mnemonic code(phrase),中文称为助记词或助记码。例如:

rose rocket invest real refuse margin festival danger anger border idle brown

BIP44:基于 BIP32 的系统,赋予树状结构中的各层特殊的意义。让同一个 seed 可以支援多币种、多帐户等。各层定义如下:

m / purpose' / coin_type' / account' / change / address_index

其中的 purporse' 固定是 44',代表使用 BIP44。而 coin_type' 用来表示不同币种,例如 Bitcoin 就是 0',Ethereum 是 60'。

产生master key

var hdWallet = hdkey.fromMasterSeed(seed)

产生第一个 Ethereum Address

产生 Wallet 中第一个帐户的第一组 keypair。可以从 Master Key生成,根据其路径 m/44'/60'/0'/0/0 推导出来。

var key1 = hdWallet.derivePath("m/44'/60'/0'/0/0")
var address1 = util.pubToAddress(key1._hdkey._publicKey, true)

参考 https://www.jianshu.com/p/54a2b14dfdf2