crypto

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const AddressHexLength = 2 * binary.Word160Length

Variables

View Source
var ZeroAddress = Address{}

Functions

func DecodePublicKeyFixedWidth

func DecodePublicKeyFixedWidth(buf []byte, publicKey *PublicKey) (int, error)

Decodes an encoded public key returning the number of bytes consumed

func EnsureEd25519PrivateKeyCorrect

func EnsureEd25519PrivateKeyCorrect(candidatePrivateKey ed25519.PrivateKey) error

Ensures the last 32 bytes of the ed25519 private key is the public key derived from the first 32 private bytes

func PublicKeyLength

func PublicKeyLength(curveType CurveType) int

Returns the length in bytes of the public key

Types

type Address

type Address binary.Word160

func AddressFromBytes

func AddressFromBytes(bs []byte) (address Address, err error)

Returns an address consisting of the first 20 bytes of bs, return an error if the bs does not have length exactly 20 but will still return either: the bytes in bs padded on the right or the first 20 bytes of bs truncated in any case.

func AddressFromHexString

func AddressFromHexString(str string) (Address, error)

func AddressFromWord256

func AddressFromWord256(addr binary.Word256) Address

func MaybeAddressFromBytes

func MaybeAddressFromBytes(bs []byte) (*Address, error)

Returns a pointer to an Address that is nil iff len(bs) == 0 otherwise does the same as AddressFromBytes

func MustAddressFromBytes

func MustAddressFromBytes(addr []byte) Address

func NewContractAddress

func NewContractAddress(caller Address, sequence uint64) (newAddr Address)

func (Address) Bytes

func (address Address) Bytes() []byte

Copy address and return a slice onto the copy

func (Address) MarshalJSON

func (address Address) MarshalJSON() ([]byte, error)

func (Address) MarshalText

func (address Address) MarshalText() ([]byte, error)

func (Address) String

func (address Address) String() string

func (*Address) UnmarshalJSON

func (address *Address) UnmarshalJSON(data []byte) error

func (*Address) UnmarshalText

func (address *Address) UnmarshalText(text []byte) error

func (Address) Word256

func (address Address) Word256() binary.Word256

type Addresses

type Addresses []Address

func (Addresses) Len

func (as Addresses) Len() int

func (Addresses) Less

func (as Addresses) Less(i, j int) bool

func (Addresses) Swap

func (as Addresses) Swap(i, j int)

type CurveType

type CurveType int8
const (
	CurveTypeSecp256k1 CurveType = iota
	CurveTypeEd25519
)

func CurveTypeFromString

func CurveTypeFromString(s string) (CurveType, error)

func (CurveType) Byte

func (k CurveType) Byte() byte

Get this CurveType's 8 bit identifier as a byte

func (CurveType) String

func (k CurveType) String() string

type ErrInvalidCurve

type ErrInvalidCurve string

func (ErrInvalidCurve) Error

func (err ErrInvalidCurve) Error() string

type PrivateKey

type PrivateKey struct {
	CurveType  CurveType
	PublicKey  []byte
	PrivateKey []byte
}

func GeneratePrivateKey

func GeneratePrivateKey(random io.Reader, curveType CurveType) (PrivateKey, error)

func PrivateKeyFromRawBytes

func PrivateKeyFromRawBytes(privKeyBytes []byte, curveType CurveType) (PrivateKey, error)

func PrivateKeyFromSecret

func PrivateKeyFromSecret(secret string, curveType CurveType) PrivateKey

func (PrivateKey) GetPublicKey

func (p PrivateKey) GetPublicKey() PublicKey

func (PrivateKey) RawBytes

func (p PrivateKey) RawBytes() []byte

func (PrivateKey) Sign

func (p PrivateKey) Sign(msg []byte) (Signature, error)

type PublicKey

type PublicKey struct {
	CurveType CurveType
	PublicKey []byte
	// contains filtered or unexported fields
}

PublicKey

func PublicKeyFromBytes

func PublicKeyFromBytes(bs []byte, curveType CurveType) (PublicKey, error)

Currently this is a stub that reads the raw bytes returned by key_client and returns an ed25519 public key.

func (PublicKey) ABCIPubKey

func (p PublicKey) ABCIPubKey() abci.PubKey

Return the ABCI PubKey. See Tendermint protobuf.go for the go-crypto conversion this is based on

func (PublicKey) Address

func (p PublicKey) Address() Address

func (PublicKey) AddressHashType

func (p PublicKey) AddressHashType() string

func (PublicKey) Encode

func (p PublicKey) Encode() []byte

Produces a binary encoding of the CurveType byte plus the public key for padded to a fixed width on the right

func (PublicKey) IsValid

func (p PublicKey) IsValid() bool

func (PublicKey) MarshalJSON

func (p PublicKey) MarshalJSON() ([]byte, error)

func (PublicKey) MarshalText

func (p PublicKey) MarshalText() ([]byte, error)

func (PublicKey) RawBytes

func (p PublicKey) RawBytes() []byte

func (PublicKey) String

func (p PublicKey) String() string

func (*PublicKey) UnmarshalJSON

func (p *PublicKey) UnmarshalJSON(text []byte) error

func (*PublicKey) UnmarshalText

func (p *PublicKey) UnmarshalText(text []byte) error

func (PublicKey) Verify

func (p PublicKey) Verify(msg []byte, signature Signature) bool

type PublicKeyJSON

type PublicKeyJSON struct {
	CurveType string
	PublicKey string
}

type Signable

type Signable interface {
	SignBytes(chainID string) ([]byte, error)
}

Signable is an interface for all signable things. It typically removes signatures before serializing.

type Signature

type Signature struct {
	Signature binary.HexBytes
}

func SignatureFromBytes

func SignatureFromBytes(bs []byte, curveType CurveType) (Signature, error)

Currently this is a stub that reads the raw bytes returned by key_client and returns an ed25519 signature.

func (Signature) RawBytes

func (sig Signature) RawBytes() []byte

type Signer

type Signer interface {
	Sign(msg []byte) (Signature, error)
}

Jump to

Keyboard shortcuts

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