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.

34 lines
787 B

10 years ago
10 years ago
  1. package account
  2. import (
  3. "github.com/tendermint/ed25519"
  4. . "github.com/tendermint/tendermint/common"
  5. )
  6. type PrivAccount struct {
  7. Address []byte
  8. PubKey PubKey
  9. PrivKey PrivKey
  10. }
  11. // Generates a new account with private key.
  12. func GenPrivAccount() *PrivAccount {
  13. privKeyBytes := new([64]byte)
  14. copy(privKeyBytes[:32], CRandBytes(32))
  15. pubKeyBytes := ed25519.MakePublicKey(privKeyBytes)
  16. pubKey := PubKeyEd25519(pubKeyBytes[:])
  17. privKey := PrivKeyEd25519(privKeyBytes[:])
  18. return &PrivAccount{
  19. Address: pubKey.Address(),
  20. PubKey: pubKey,
  21. PrivKey: privKey,
  22. }
  23. }
  24. func (privAccount *PrivAccount) Sign(o Signable) Signature {
  25. return privAccount.PrivKey.Sign(SignBytes(o))
  26. }
  27. func (privAccount *PrivAccount) String() string {
  28. return Fmt("PrivAccount{%X}", privAccount.Address)
  29. }