mirror of
https://github.com/tendermint/tendermint.git
synced 2025-12-23 14:25:19 +00:00
* libs/common: Refactor libs/common 4 - move byte function out of cmn to its own pkg - move tempfile out of cmn to its own pkg - move throttletimer to its own pkg ref #4147 Signed-off-by: Marko Baricevic <marbar3778@yahoo.com> * add changelog entry * fix linting issues
41 lines
952 B
Go
41 lines
952 B
Go
package crypto
|
|
|
|
import (
|
|
"github.com/tendermint/tendermint/crypto/tmhash"
|
|
"github.com/tendermint/tendermint/libs/bytes"
|
|
)
|
|
|
|
const (
|
|
// AddressSize is the size of a pubkey address.
|
|
AddressSize = tmhash.TruncatedSize
|
|
)
|
|
|
|
// An address is a []byte, but hex-encoded even in JSON.
|
|
// []byte leaves us the option to change the address length.
|
|
// Use an alias so Unmarshal methods (with ptr receivers) are available too.
|
|
type Address = bytes.HexBytes
|
|
|
|
func AddressHash(bz []byte) Address {
|
|
return Address(tmhash.SumTruncated(bz))
|
|
}
|
|
|
|
type PubKey interface {
|
|
Address() Address
|
|
Bytes() []byte
|
|
VerifyBytes(msg []byte, sig []byte) bool
|
|
Equals(PubKey) bool
|
|
}
|
|
|
|
type PrivKey interface {
|
|
Bytes() []byte
|
|
Sign(msg []byte) ([]byte, error)
|
|
PubKey() PubKey
|
|
Equals(PrivKey) bool
|
|
}
|
|
|
|
type Symmetric interface {
|
|
Keygen() []byte
|
|
Encrypt(plaintext []byte, secret []byte) (ciphertext []byte)
|
|
Decrypt(ciphertext []byte, secret []byte) (plaintext []byte, err error)
|
|
}
|