forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto.go
75 lines (64 loc) · 1.4 KB
/
crypto.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
69
70
71
72
73
74
75
package crypto
import (
"fmt"
)
type CurveType uint32
const (
CurveTypeUnset CurveType = iota
CurveTypeEd25519
CurveTypeSecp256k1
)
func (k CurveType) String() string {
switch k {
case CurveTypeSecp256k1:
return "secp256k1"
case CurveTypeEd25519:
return "ed25519"
case CurveTypeUnset:
return ""
default:
return "unknown"
}
}
func (k CurveType) ABCIType() string {
switch k {
case CurveTypeSecp256k1:
return "secp256k1"
case CurveTypeEd25519:
return "ed25519"
case CurveTypeUnset:
return ""
default:
return "unknown"
}
}
// Get this CurveType's 8 bit identifier as a byte
func (k CurveType) Byte() byte {
return byte(k)
}
func CurveTypeFromString(s string) (CurveType, error) {
switch s {
case "secp256k1":
return CurveTypeSecp256k1, nil
case "ed25519":
return CurveTypeEd25519, nil
case "":
return CurveTypeUnset, nil
default:
return CurveTypeUnset, ErrInvalidCurve(s)
}
}
type ErrInvalidCurve string
func (err ErrInvalidCurve) Error() string {
return fmt.Sprintf("invalid curve type")
}
// The types in this file allow us to control serialisation of keys and signatures, as well as the interface
// exposed regardless of crypto library
type Signer interface {
Sign(msg []byte) (Signature, error)
}
// Signable is an interface for all signable things.
// It typically removes signatures before serializing.
type Signable interface {
SignBytes(chainID string) ([]byte, error)
}