OSDN Git Service

rename (#465)
[bytom/vapor.git] / p2p / signlib / chainkd.go
1 package signlib
2
3 import (
4         "errors"
5
6         "github.com/bytom/vapor/crypto/ed25519/chainkd"
7 )
8
9 const (
10         PubkeySize     = 64
11         AuthSigMsgSize = 132
12 )
13
14 var (
15         ErrPubkeyLength = errors.New("pubkey length error")
16 )
17
18 type PubKey interface {
19         String() string
20         Bytes() []byte
21         Verify(msg []byte, sig []byte) bool
22         MarshalText() ([]byte, error)
23 }
24
25 type PrivKey interface {
26         Bytes() []byte
27         Sign(msg []byte) []byte
28         XPub() chainkd.XPub
29 }
30
31 func NewPrivKey() (PrivKey, error) {
32         return chainkd.NewXPrv(nil)
33 }
34
35 func NewPubKey(pubkey []byte) (PubKey, error) {
36         if len(pubkey) != PubkeySize {
37                 return nil, ErrPubkeyLength
38         }
39
40         var pubKey chainkd.XPub
41         copy(pubKey[:], pubkey[:])
42         return pubKey, nil
43 }