-
Notifications
You must be signed in to change notification settings - Fork 6
/
curve.go
49 lines (43 loc) · 1.06 KB
/
curve.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
package crypto
import "github.com/pkg/errors"
// ECKind -
type ECKind int
const (
KindEd25519 ECKind = iota + 1
KindSecp256k1
KindNistP256
)
// Curve -
type Curve interface {
GeneratePrivateKey() ([]byte, []byte, error)
GetPublicKey(privateKey []byte) ([]byte, error)
Sign(data []byte, privateKey []byte) (Signature, error)
Verify(data []byte, signature []byte, pubKey []byte) bool
AddressPrefix() []byte
PublicKeyPrefix() []byte
Kind() ECKind
}
// NewCurve -
func NewCurve(kind ECKind) (Curve, error) {
switch kind {
case KindEd25519:
return NewEd25519(), nil
// case KindSecp256k1:
// case KindNistP256:
default:
return nil, errors.Errorf("unknown curve kind: %d", kind)
}
}
// NewCurveFromPrefix -
func NewCurveFromPrefix(prefix string) (Curve, error) {
switch prefix {
case "edsig", "edsk", "edpk", "tz1", "edesk":
return NewEd25519(), nil
// case "spsig", "sppk", "spsk", "tz2", "spesk":
// // Secp256k1
// case "p2sig", "p2pk", "p2sk", "tz3", "p2esk":
// // NistP256
default:
return nil, errors.Errorf("unknown curve prefix: %s", prefix)
}
}