-
Notifications
You must be signed in to change notification settings - Fork 0
/
key.go
50 lines (43 loc) · 1.13 KB
/
key.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
package signer
import (
"io/ioutil"
"log"
"strings"
yaml "gopkg.in/yaml.v2"
)
// A Key identifies a key preloaded in your HSM
type Key struct {
Name string `yaml:"Name"`
PublicKeyHash string `yaml:"PublicKeyHash"`
PublicKey string `yaml:"PublicKey"`
HsmSlot uint `yaml:"HsmSlot"`
HsmLabel string `yaml:"HsmLabel"`
}
// Curve represented by this key
func (key *Key) Curve() int {
if strings.HasPrefix(key.PublicKeyHash, "tz1") {
return curveEd25519
} else if strings.HasPrefix(key.PublicKeyHash, "tz2") {
return curveSecp256k1
} else if strings.HasPrefix(key.PublicKeyHash, "tz3") {
return curveNistP256
}
return curveUnknown
}
// IsECDSA Curve or EdDSA Curve
func (key *Key) IsECDSA() bool {
return key.Curve() == curveNistP256 || key.Curve() == curveSecp256k1
}
// LoadKeyFile loads keys from a file
func LoadKeyFile(keyfile string) []Key {
keys := []Key{}
yamlFile, err := ioutil.ReadFile(keyfile)
if err != nil {
log.Fatalln("Unable to read file: " + keyfile)
}
err = yaml.Unmarshal(yamlFile, &keys)
if err != nil {
log.Fatalln("Unable to parse yaml file: " + keyfile)
}
return keys
}