-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathhdwallet.go
56 lines (47 loc) · 1.19 KB
/
hdwallet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// tokucore
//
// Copyright 2019 by KeyFuse Labs
// BSD License
package main
import (
"fmt"
"github.com/keyfuse/tokucore/network"
"github.com/keyfuse/tokucore/xcore/bip32"
)
// Bitcoin HD wallet demo.
func main() {
net := network.TestNet
seed := []byte("bitcoin blockchain tokublock sandbox")
hdkey := bip32.NewHDKey(seed)
// Master Private Key.
masterprv := hdkey.ToString(net)
fmt.Printf("master.prvkey:%v\n", masterprv)
// bitcoin path: m/44'/0'/0'/0
{
for i := 0; i < 2; i++ {
path := fmt.Sprintf("m/44'/0'/0'/%d", i)
prvkey, err := hdkey.DeriveByPath(path)
if err != nil {
panic(err)
}
fmt.Printf("btc.chain:%v\n", path)
fmt.Printf("\tchild.prvkey:%v\n", prvkey.ToString(net))
pubkey := prvkey.HDPublicKey()
fmt.Printf("\tchild.pubkey:%v\n", pubkey.ToString(net))
}
}
// ethereum path: m/44'/60'/0'/0
{
for i := 0; i < 2; i++ {
path := fmt.Sprintf("m/44'/60'/0'/%d", i)
prvkey, err := hdkey.DeriveByPath(path)
if err != nil {
panic(err)
}
fmt.Printf("eth.chain:%v\n", path)
fmt.Printf("\tchild.prvkey:%v\n", prvkey.ToString(net))
pubkey := prvkey.HDPublicKey()
fmt.Printf("\tchild.pubkey:%v\n", pubkey.ToString(net))
}
}
}