2014-12-17 01:37:13 -08:00
|
|
|
package account
|
2014-12-09 18:49:04 -08:00
|
|
|
|
|
|
|
import (
|
2015-01-18 06:34:01 -08:00
|
|
|
"github.com/tendermint/ed25519"
|
2014-12-09 18:49:04 -08:00
|
|
|
. "github.com/tendermint/tendermint/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PrivAccount struct {
|
2015-01-11 23:12:33 -08:00
|
|
|
Address []byte
|
2014-12-09 18:49:04 -08:00
|
|
|
PubKey PubKey
|
|
|
|
PrivKey PrivKey
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generates a new account with private key.
|
|
|
|
func GenPrivAccount() *PrivAccount {
|
2015-01-18 06:34:01 -08:00
|
|
|
privKeyBytes := new([64]byte)
|
|
|
|
copy(privKeyBytes[:32], CRandBytes(32))
|
|
|
|
pubKeyBytes := ed25519.MakePublicKey(privKeyBytes)
|
|
|
|
pubKey := PubKeyEd25519(pubKeyBytes[:])
|
|
|
|
privKey := PrivKeyEd25519(privKeyBytes[:])
|
2014-12-09 18:49:04 -08:00
|
|
|
return &PrivAccount{
|
2015-01-18 06:34:01 -08:00
|
|
|
Address: pubKey.Address(),
|
|
|
|
PubKey: pubKey,
|
2015-01-13 21:03:01 -08:00
|
|
|
PrivKey: privKey,
|
2014-12-09 18:49:04 -08:00
|
|
|
}
|
|
|
|
}
|
2014-12-17 01:37:13 -08:00
|
|
|
|
|
|
|
func (privAccount *PrivAccount) Sign(o Signable) Signature {
|
|
|
|
return privAccount.PrivKey.Sign(SignBytes(o))
|
|
|
|
}
|
2015-01-16 00:31:34 -08:00
|
|
|
|
|
|
|
func (privAccount *PrivAccount) String() string {
|
|
|
|
return Fmt("PrivAccount{%X}", privAccount.Address)
|
|
|
|
}
|