|
|
@ -10,6 +10,7 @@ import ( |
|
|
|
// PrivKey is part of PrivAccount and state.PrivValidator.
|
|
|
|
type PrivKey interface { |
|
|
|
Sign(msg []byte) Signature |
|
|
|
PubKey() PubKey |
|
|
|
} |
|
|
|
|
|
|
|
// Types of PrivKey implementations
|
|
|
@ -26,24 +27,22 @@ var _ = RegisterInterface( |
|
|
|
//-------------------------------------
|
|
|
|
|
|
|
|
// Implements PrivKey
|
|
|
|
type PrivKeyEd25519 struct { |
|
|
|
PubKey []byte |
|
|
|
PrivKey []byte |
|
|
|
} |
|
|
|
type PrivKeyEd25519 []byte |
|
|
|
|
|
|
|
func (key PrivKeyEd25519) TypeByte() byte { return PrivKeyTypeEd25519 } |
|
|
|
|
|
|
|
func (key PrivKeyEd25519) ValidateBasic() error { |
|
|
|
if len(key.PubKey) != ed25519.PublicKeySize { |
|
|
|
return errors.New("Invalid PrivKeyEd25519 pubkey size") |
|
|
|
} |
|
|
|
if len(key.PrivKey) != ed25519.PrivateKeySize { |
|
|
|
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.PrivKey, key.PubKey) |
|
|
|
signature := ed25519.SignMessage(msg, key, ed25519.MakePubKey(key)) |
|
|
|
return SignatureEd25519(signature) |
|
|
|
} |
|
|
|
|
|
|
|
func (key PrivKeyEd25519) PubKey() PubKey { |
|
|
|
return PubKeyEd25519(ed25519.MakePubKey(key)) |
|
|
|
} |