crypto

package
v0.0.0-...-0a11024 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: Apache-2.0 Imports: 9 Imported by: 27

README

crypto

crypto is the cryptographic package adapted for Tendermint's uses

Importing it

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

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

If you want to decode bytes into one of the types, but don't care about the specific algorithm, use import "github.com/tendermint/classic/crypto/amino"

Binary encoding

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

JSON Encoding

crypto .Bytes() uses Amino:binary encoding, but Amino:JSON is also supported.

Example Amino:JSON encodings:

ed25519.PrivKeyEd25519     - {"type":"954568A3288910","value":"EVkqJO/jIXp3rkASXfh9YnyToYXRXhBr6g9cQVxPFnQBP/5povV4HTjvsy530kybxKHwEi85iU8YL0qQhSYVoQ=="}
ed25519.PubKeyEd25519      - {"type":"AC26791624DE60","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="}
crypto.PrivKeySecp256k1   - {"type":"019E82E1B0F798","value":"zx4Pnh67N+g2V+5vZbQzEyRerX9c4ccNZOVzM9RvJ0Y="}
crypto.PubKeySecp256k1    - {"type":"F8CCEAEB5AE980","value":"A8lPKJXcNl5VHt1FK8a244K9EJuS4WX1hFBnwisi0IJx"}

Documentation

Index

Examples

Constants

View Source
const (
	// AddressSize is the size of a pubkey address.
	AddressSize = tmhash.TruncatedSize
)
View Source
const Version = "v1.0.0-rc.0"

Variables

This section is empty.

Functions

func CRandBytes

func CRandBytes(numBytes int) []byte

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

Returns a crand.Reader.

func Sha256

func Sha256(bytes []byte) []byte
Example
package main

import (
	"fmt"

	"github.com/tendermint/classic/crypto"
)

func main() {
	sum := crypto.Sha256([]byte("This is Tendermint"))
	fmt.Printf("%x\n", sum)
}
Output:

f91afb642f3d1c87c17eb01aae5cb65c242dfdbe7cf1066cc260f4ce5d33b94e

Types

type Address

type Address [AddressSize]byte

(truncated) hash of some preimage (typically of a pubkey).

func AddressFromBytes

func AddressFromBytes(bz []byte) (ret Address)

func AddressFromID

func AddressFromID(id ID) (addr Address, err error)

func AddressFromPreimage

func AddressFromPreimage(bz []byte) Address

func AddressFromString

func AddressFromString(str string) (addr Address, err error)

func MustAddressFromString

func MustAddressFromString(str string) (addr Address)

func (Address) Bytes

func (addr Address) Bytes() []byte

func (Address) Compare

func (addr Address) Compare(other Address) int

func (*Address) DecodeID

func (addr *Address) DecodeID(id ID) error

func (*Address) DecodeString

func (addr *Address) DecodeString(str string) error

func (Address) ID

func (addr Address) ID() ID

func (Address) IsZero

func (addr Address) IsZero() bool

func (Address) String

func (addr Address) String() string

type ID

type ID string

The bech32 representation w/ prefix "c".

func (ID) IsZero

func (id ID) IsZero() bool

func (ID) String

func (id ID) String() string

func (ID) Validate

func (id ID) Validate() error

type PrivKey

type PrivKey interface {
	// Stable
	Bytes() []byte
	Sign(msg []byte) ([]byte, error)
	PubKey() PubKey
	Equals(PrivKey) bool
}

All operations must be deterministic.

func PrivKeyFromBytes

func PrivKeyFromBytes(privKeyBytes []byte) (privKey PrivKey, err error)

type PubKey

type PubKey interface {
	// Stable
	Address() Address
	Bytes() []byte
	VerifyBytes(msg []byte, sig []byte) bool
	Equals(PubKey) bool

	// Unstable
	String() string
}

All operations must be deterministic.

func PubKeyFromBytes

func PubKeyFromBytes(pubKeyBytes []byte) (pubKey PubKey, err error)

type Symmetric

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

Directories

Path Synopsis
pb
internal
Package merkle computes a deterministic minimal height Merkle tree hash.
Package merkle computes a deterministic minimal height Merkle tree hash.
pb
pb
internal/secp256k1
nolint:gocritic Package secp256k1 wraps the bitcoin secp256k1 C library.
nolint:gocritic Package secp256k1 wraps the bitcoin secp256k1 C library.
pb
Package xchacha20poly1305 creates an AEAD using hchacha, chacha, and poly1305 This allows for randomized nonces to be used in conjunction with chacha.
Package xchacha20poly1305 creates an AEAD using hchacha, chacha, and poly1305 This allows for randomized nonces to be used in conjunction with chacha.

Jump to

Keyboard shortcuts

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