-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.go
More file actions
44 lines (37 loc) · 1.11 KB
/
path.go
File metadata and controls
44 lines (37 loc) · 1.11 KB
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
package hdwallets
import (
"fmt"
"github.com/btcsuite/btcutil/hdkeychain"
)
// m / purpose' / coin_type' / account' / change / address_index
type DerivationPath struct {
Purpose uint32
CoinType uint32
Account uint32
Change uint32
AddressIndex uint32
}
func NewBIP44DerivationPath(coinType,account,change,addressIndex uint32) *DerivationPath{
return NewDerivationPath(44,coinType,account,change,addressIndex)
}
func NewDerivationPath(purpose,coinType,account,change,addressIndex uint32) *DerivationPath{
return &DerivationPath{
Purpose: purpose + hdkeychain.HardenedKeyStart,
CoinType: coinType + hdkeychain.HardenedKeyStart,
Account: account + hdkeychain.HardenedKeyStart,
Change: change,
AddressIndex: addressIndex,
}
}
func (d *DerivationPath) PathString() string{
return fmt.Sprintf("m/%d'/%d'/%d'/%d/%d",d.Purpose-hdkeychain.HardenedKeyStart,d.CoinType-hdkeychain.HardenedKeyStart,d.Account-hdkeychain.HardenedKeyStart,d.Change,d.AddressIndex)
}
func (d *DerivationPath) Path() []uint32{
return []uint32{
d.Purpose,
d.CoinType,
d.Account,
d.Change,
d.AddressIndex,
}
}