-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtesting.go
68 lines (52 loc) · 1.63 KB
/
testing.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
57
58
59
60
61
62
63
64
65
66
67
68
package bip32
import (
"encoding/hex"
"io"
"strconv"
"strings"
)
// This file specify some utility structure to ease testing.
//go:generate go run golden.go
// GoldenBase base directory storing the golden files
const GoldenBase = "testdata"
// GoldenName specifies the file containing the reference test vectors
const GoldenName = "bip32.golden"
// GoldenAddOnName specifies the file containing the more test vectors
// from the btcutil/hdkeychain testing
const GoldenAddOnName = "bip32_addon.golden"
// ChainGoldie is the structure for key chains
type ChainGoldie struct {
Path Path // child stemming from master node
ExtendedPublicKey string
ExtendedPrivateKey string
}
// ChildIndex is enhanced index capable of telling whether its hardened.
type ChildIndex struct {
Index uint32
Hardened bool
}
// Goldie is the structure of a single test vector.
type Goldie struct {
Seed string
Chains []ChainGoldie
}
// Path alias string with a path decoding api
type Path string
// ChildIndices return the child indices tree along this path
func (path Path) ChildIndices() ([]*ChildIndex, error) {
indices := strings.Split(string(path), "/")
childs := make([]*ChildIndex, len(indices)-1)
for i, v := range indices[1:] { // skip the root
hardened := strings.HasSuffix(v, "H")
index, err := strconv.Atoi(strings.TrimSuffix(v, "H"))
if nil != err {
return nil, err
}
childs[i] = &ChildIndex{Index: uint32(index), Hardened: hardened}
}
return childs, nil
}
// NewEntropyReader constructs hex decoder for testing.
func NewEntropyReader(hexStr string) io.Reader {
return hex.NewDecoder(strings.NewReader(hexStr))
}