github.com/aakash4dev/cometbft@v0.38.2/crypto/crypto.go (about)

     1  package crypto
     2  
     3  import (
     4  	"github.com/aakash4dev/cometbft/crypto/tmhash"
     5  	"github.com/aakash4dev/cometbft/libs/bytes"
     6  )
     7  
     8  const (
     9  	// AddressSize is the size of a pubkey address.
    10  	AddressSize = tmhash.TruncatedSize
    11  )
    12  
    13  // An address is a []byte, but hex-encoded even in JSON.
    14  // []byte leaves us the option to change the address length.
    15  // Use an alias so Unmarshal methods (with ptr receivers) are available too.
    16  type Address = bytes.HexBytes
    17  
    18  func AddressHash(bz []byte) Address {
    19  	return Address(tmhash.SumTruncated(bz))
    20  }
    21  
    22  type PubKey interface {
    23  	Address() Address
    24  	Bytes() []byte
    25  	VerifySignature(msg []byte, sig []byte) bool
    26  	Equals(PubKey) bool
    27  	Type() string
    28  }
    29  
    30  type PrivKey interface {
    31  	Bytes() []byte
    32  	Sign(msg []byte) ([]byte, error)
    33  	PubKey() PubKey
    34  	Equals(PrivKey) bool
    35  	Type() string
    36  }
    37  
    38  type Symmetric interface {
    39  	Keygen() []byte
    40  	Encrypt(plaintext []byte, secret []byte) (ciphertext []byte)
    41  	Decrypt(ciphertext []byte, secret []byte) (plaintext []byte, err error)
    42  }
    43  
    44  // If a new key type implements batch verification,
    45  // the key type must be registered in github.com/aakash4dev/cometbft/crypto/batch
    46  type BatchVerifier interface {
    47  	// Add appends an entry into the BatchVerifier.
    48  	Add(key PubKey, message, signature []byte) error
    49  	// Verify verifies all the entries in the BatchVerifier, and returns
    50  	// if every signature in the batch is valid, and a vector of bools
    51  	// indicating the verification status of each signature (in the order
    52  	// that signatures were added to the batch).
    53  	Verify() (bool, []bool)
    54  }