You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

48 lines
1.0 KiB

package account
import (
"errors"
"github.com/tendermint/go-ed25519"
. "github.com/tendermint/tendermint/binary"
)
// PrivKey is part of PrivAccount and state.PrivValidator.
type PrivKey interface {
Sign(msg []byte) Signature
PubKey() PubKey
}
// Types of PrivKey implementations
const (
PrivKeyTypeEd25519 = byte(0x01)
)
// for binary.readReflect
var _ = RegisterInterface(
struct{ PrivKey }{},
ConcreteType{PrivKeyEd25519{}},
)
//-------------------------------------
// Implements PrivKey
type PrivKeyEd25519 []byte
func (key PrivKeyEd25519) TypeByte() byte { return PrivKeyTypeEd25519 }
func (key PrivKeyEd25519) ValidateBasic() error {
if len(key) != ed25519.PrivateKeySize {
return errors.New("Invalid PrivKeyEd25519 privkey size")
}
return nil
}
func (key PrivKeyEd25519) Sign(msg []byte) Signature {
signature := ed25519.SignMessage(msg, key, ed25519.MakePubKey(key))
return SignatureEd25519(signature)
}
func (key PrivKeyEd25519) PubKey() PubKey {
return PubKeyEd25519(ed25519.MakePubKey(key))
}