crypto

package
v0.0.0-...-be384fd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

crypto

crypto is the cryptographic package adapted for Tendermint's uses

Importing it

To get the interfaces, import "github.com/tendermint/tendermint/crypto"

For any specific algorithm, use its specific module e.g. import "github.com/tendermint/tendermint/crypto/ed25519"

Binary encoding

For Binary encoding, please refer to the Tendermint encoding specification.

JSON Encoding

JSON encoding is done using tendermint's internal json encoder. For more information on JSON encoding, please refer to Tendermint JSON encoding

Example JSON encodings:

ed25519.PrivKey     - {"type":"tendermint/PrivKeyEd25519","value":"EVkqJO/jIXp3rkASXfh9YnyToYXRXhBr6g9cQVxPFnQBP/5povV4HTjvsy530kybxKHwEi85iU8YL0qQhSYVoQ=="}
ed25519.PubKey      - {"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="}
sr25519.PrivKeySr25519   - {"type":"tendermint/PrivKeySr25519","value":"xtYVH8UCIqfrY8FIFc0QEpAEBShSG4NT0zlEOVSZ2w4="}
sr25519.PubKeySr25519    - {"type":"tendermint/PubKeySr25519","value":"8sKBLKQ/OoXMcAJVxBqz1U7TyxRFQ5cmliuHy4MrF0s="}
crypto.PrivKeySecp256k1   - {"type":"tendermint/PrivKeySecp256k1","value":"zx4Pnh67N+g2V+5vZbQzEyRerX9c4ccNZOVzM9RvJ0Y="}
crypto.PubKeySecp256k1    - {"type":"tendermint/PubKeySecp256k1","value":"A8lPKJXcNl5VHt1FK8a244K9EJuS4WX1hFBnwisi0IJx"}

Documentation

Index

Constants

View Source
const (
	// HashSize is the size in bytes of an AddressHash.
	HashSize = sha256.Size

	// AddressSize is the size of a pubkey address.
	AddressSize        = 20
	DefaultHashSize    = 32
	DefaultAppHashSize = DefaultHashSize
	ProTxHashSize      = DefaultHashSize
	QuorumHashSize     = DefaultHashSize
)

Variables

View Source
var (
	// ErrInvalidProTxHash uses in proTxHash validation
	ErrInvalidProTxHash = errors.New("proTxHash is invalid")
)

Functions

func CRandBytes

func CRandBytes(numBytes int) []byte

CRandBytes this only uses the OS's randomness

func CRandHex

func CRandHex(numDigits int) string

CRandHex returns a hex encoded string that's floor(numDigits/2) * 2 long.

Note: CRandHex(24) gives 96 bits of randomness that are usually strong enough for most purposes.

func CReader

func CReader() io.Reader

CReader returns a crand.Reader.

func Checksum

func Checksum(bz []byte) []byte

Checksum returns the SHA256 of the bz.

func ProTxHashValidate

func ProTxHashValidate(val ProTxHash) error

ProTxHashValidate validates the proTxHash value

func SmallQuorumType

func SmallQuorumType() btcjson.LLMQType

Types

type Address

type Address = tmbytes.HexBytes

Address is 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.

func AddressHash

func AddressHash(bz []byte) Address

AddressHash computes a truncated SHA-256 hash of bz for use as a peer address.

See: https://docs.tendermint.com/master/spec/core/data_structures.html#address

type BatchVerifier

type BatchVerifier interface {
	// Add appends an entry into the BatchVerifier.
	Add(key PubKey, message, signature []byte) error
	// Verify verifies all the entries in the BatchVerifier, and returns
	// if every signature in the batch is valid, and a vector of bools
	// indicating the verification status of each signature (in the order
	// that signatures were added to the batch).
	Verify() (bool, []bool)
}

BatchVerifier If a new key type implements batch verification, the key type must be registered in github.com/hellarcore/tenderhellar/crypto/batch

type HexStringer

type HexStringer interface {
	HexString() string
}

HexStringer ...

type KeyType

type KeyType int
const (
	Ed25519 KeyType = iota
	BLS12381
	Secp256k1
	KeyTypeAny
)

type PrivKey

type PrivKey interface {
	Bytes() []byte
	Sign(msg []byte) ([]byte, error)
	SignDigest(msg []byte) ([]byte, error)
	PubKey() PubKey
	Equals(PrivKey) bool
	Type() string

	// Implementations must support tagged encoding in JSON.
	jsontypes.Tagged
}

type ProTxHash

type ProTxHash = tmbytes.HexBytes

func ProTxHashFromSeedBytes

func ProTxHashFromSeedBytes(bz []byte) ProTxHash

func RandProTxHash

func RandProTxHash() ProTxHash

func RandProTxHashes

func RandProTxHashes(n int) []ProTxHash

RandProTxHashes generates and returns a list of N random generated proTxHashes

type PubKey

type PubKey interface {
	Address() Address
	Bytes() []byte
	VerifySignature(msg []byte, sig []byte) bool
	VerifySignatureDigest(hash []byte, sig []byte) bool
	Equals(PubKey) bool
	Type() string

	// Implementations must support tagged encoding in JSON.
	jsontypes.Tagged
	fmt.Stringer
	HexStringer
}

type QuorumHash

type QuorumHash = tmbytes.HexBytes

func RandQuorumHash

func RandQuorumHash() QuorumHash

type QuorumKeys

type QuorumKeys struct {
	PrivKey            PrivKey
	PubKey             PubKey
	ThresholdPublicKey PubKey
}

func (QuorumKeys) MarshalJSON

func (pvKey QuorumKeys) MarshalJSON() ([]byte, error)

func (*QuorumKeys) UnmarshalJSON

func (pvKey *QuorumKeys) UnmarshalJSON(data []byte) error

type SortProTxHash

type SortProTxHash []ProTxHash

func (SortProTxHash) Len

func (sptxh SortProTxHash) Len() int

func (SortProTxHash) Less

func (sptxh SortProTxHash) Less(i, j int) bool

func (SortProTxHash) Swap

func (sptxh SortProTxHash) Swap(i, j int)

type Symmetric

type Symmetric interface {
	Keygen() []byte
	Encrypt(plaintext []byte, secret []byte) (ciphertext []byte)
	Decrypt(ciphertext []byte, secret []byte) (plaintext []byte, err error)
}

type Validator

type Validator interface {
	Validate() error
}

Validator is a validator interface

Directories

Path Synopsis
internal
Package merkle computes a deterministic minimal height Merkle tree hash.
Package merkle computes a deterministic minimal height Merkle tree hash.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL