ed25519

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package crypto provides key and address creation functions.

Index

Constants

This section is empty.

Variables

View Source
var EmptyPublicKey = PublicKey([util.Length32]byte{})

EmptyPublicKey is an empty PublicKey

Functions

func BytesToPushKeyID

func BytesToPushKeyID(pk []byte) string

BytesToPushKeyID returns bech32 address corresponding to a push key. Panics if pk is not a valid ed25519 public key

func ConvertBase58PrivKeyToTMPrivKey

func ConvertBase58PrivKeyToTMPrivKey(b58PrivKey string) (ed25519.PrivKey, error)

ConvertBase58PrivKeyToTMPrivKey converts base58 private key to tendermint's ed25519.PrivKeyEd25519

func ConvertBase58PubKeyToTMPubKey

func ConvertBase58PubKeyToTMPubKey(b58PubKey string) (ed25519.PubKey, error)

ConvertBase58PubKeyToTMPubKey converts base58 public key to tendermint's ed25519.PubKeyEd25519

func CreatePushKeyID

func CreatePushKeyID(pk PublicKey) string

CreatePushKeyID returns bech32 address corresponding to a push key. Panics if pk is not a valid ed25519 public key

func DecodeAddr

func DecodeAddr(addr string) ([20]byte, error)

DecodeAddr validates an address, decodes it and returns raw encoded 20-bytes address

func DecodeAddrOnly

func DecodeAddrOnly(addr string) ([20]byte, error)

DecodeAddrOnly is like DecodeAddr except it does not validate the address

func IsValidPrivKey

func IsValidPrivKey(privKey string) error

IsValidPrivKey checks whether a private key is valid

func IsValidPubKey

func IsValidPubKey(pubKey string) error

IsValidPubKey checks whether a public key is valid

func IsValidPushAddr

func IsValidPushAddr(addr string) error

IsValidPushAddr checks whether addr is a valid network push address

func IsValidUserAddr

func IsValidUserAddr(addr string) error

IsValidUserAddr checks whether addr is a valid user account address

func MustBase58FromPubKeyBytes

func MustBase58FromPubKeyBytes(pk []byte) string

MustBase58FromPubKeyBytes takes a raw public key bytes and returns its base58 encoded version. It panics if pk is invalid

func RIPEMD160ToAddr

func RIPEMD160ToAddr(hash [20]byte) util.String

RIPEMD160ToAddr returns a 20 byte slice to an address

func ToBase58PubKey

func ToBase58PubKey(bz util.Bytes32) string

ToBase58PubKey tries to convert the bytes to a base58-encoded public key. Panics if unable to convert.

Types

type FilePV

type FilePV struct {
	*privval.FilePV
}

FilePV wraps and extends tendermint's privval.FilePV

func GenerateWrappedPV

func GenerateWrappedPV(secret []byte) *FilePV

GenerateWrappedPV generate a wrapped tendermint private validator key

func (*FilePV) GetKey

func (pv *FilePV) GetKey() (*Key, error)

GetKey returns the validator's private key coerced to a crypto.Key.

type Key

type Key struct {
	Meta map[string]interface{}
	// contains filtered or unexported fields
}

Key includes a wrapped Ed25519 private key and convenient methods to get the corresponding public key and transaction address.

func NewKey

func NewKey(seed *int64) (*Key, error)

NewKey creates a new Ed25519 key

func NewKeyFromIntSeed

func NewKeyFromIntSeed(seed int) *Key

NewKeyFromIntSeed is like NewKey but accepts seed of type Int and casts to Int64.

func NewKeyFromPrivKey

func NewKeyFromPrivKey(sk *PrivKey) *Key

NewKeyFromPrivKey creates a new Key instance from a PrivKey

func (*Key) Addr

func (k *Key) Addr() identifier.Address

Addr returns the network account address corresponding the key

func (*Key) PeerID

func (k *Key) PeerID() string

PeerID returns the IPFS compatible peer ID

func (*Key) PrivKey

func (k *Key) PrivKey() *PrivKey

PrivKey returns the private key

func (*Key) PubKey

func (k *Key) PubKey() *PubKey

PubKey returns the public key

func (*Key) PushAddr

func (k *Key) PushAddr() identifier.Address

PushAddr returns the network pusher address corresponding the key

type PrivKey

type PrivKey struct {
	// contains filtered or unexported fields
}

PrivKey represents a private key

func PrivKeyFromBase58

func PrivKeyFromBase58(pk string) (*PrivKey, error)

PrivKeyFromBase58 decodes a base58 encoded private key

func PrivKeyFromBytes

func PrivKeyFromBytes(bz []byte) (*PrivKey, error)

PrivKeyFromBytes returns a PrivKey instance from a 64 bytes private key

func PrivKeyFromTMPrivateKey

func PrivKeyFromTMPrivateKey(tmSk ed25519.PrivKey) (*PrivKey, error)

PrivKeyFromTMPrivateKey encodes a tendermint private key to PrivKey

func (*PrivKey) BLSKey

func (p *PrivKey) BLSKey() *bdn.PrivateKey

BLSKey derives a BLS key using the PrivKey as seed. It uses the first 32 bytes of the private key to seed the BLS key generator. TODO: Use actual BLS private key instead of BN256

func (*PrivKey) Base58

func (p *PrivKey) Base58() string

Base58 returns the public key in base58 encoding

func (*PrivKey) Bytes

func (p *PrivKey) Bytes() ([]byte, error)

Bytes returns the byte equivalent of the public key

func (*PrivKey) Bytes64

func (p *PrivKey) Bytes64() (util.Bytes64, error)

Bytes64 is like Bytes but returns util.Bytes64

func (*PrivKey) Key

func (p *PrivKey) Key() crypto.PrivKey

Key returns the wrapped crypto.PrivKey

func (*PrivKey) Marshal

func (p *PrivKey) Marshal() ([]byte, error)

Marshal encodes the private key using protocol buffer

func (*PrivKey) MustBytes

func (p *PrivKey) MustBytes() []byte

MustBytes is like bytes but panics on error

func (*PrivKey) MustSign

func (p *PrivKey) MustSign(data []byte) []byte

MustSign signs a message but panics if error occurs

func (*PrivKey) Sign

func (p *PrivKey) Sign(data []byte) ([]byte, error)

Sign signs a message

func (*PrivKey) VRFKey

func (p *PrivKey) VRFKey() vrf.PrivateKey

VRFKey derives a VRF key using the PrivKey as seed.

type PubKey

type PubKey struct {
	// contains filtered or unexported fields
}

PubKey represents a public key

func MustPubKeyFromBytes

func MustPubKeyFromBytes(pk []byte) *PubKey

MustPubKeyFromBytes is like PubKeyFromBytes, except it panics if pk is invalid

func PubKeyFromBase58

func PubKeyFromBase58(pk string) (*PubKey, error)

PubKeyFromBase58 decodes a base58 encoded public key

func PubKeyFromBytes

func PubKeyFromBytes(pk []byte) (*PubKey, error)

PubKeyFromBytes returns a PubKey instance from a 32 bytes public key

func (*PubKey) Addr

func (p *PubKey) Addr() identifier.Address

Addr returns the bech32 account address

func (*PubKey) AddrRaw

func (p *PubKey) AddrRaw() []byte

AddrRaw returns the 20 bytes hash of the public key

func (*PubKey) Base58

func (p *PubKey) Base58() string

Base58 returns the public key in base58 encoding

func (*PubKey) Bytes

func (p *PubKey) Bytes() ([]byte, error)

Bytes returns the byte equivalent of the public key

func (*PubKey) Hex

func (p *PubKey) Hex() string

Hex returns the public key in hex encoding

func (*PubKey) MustBytes

func (p *PubKey) MustBytes() []byte

MustBytes is like Bytes but panics on error

func (*PubKey) MustBytes32

func (p *PubKey) MustBytes32() util.Bytes32

MustBytes32 is like Bytes but panics on error

func (*PubKey) PushAddr

func (p *PubKey) PushAddr() identifier.Address

PushAddr returns a bech32 pusher address

func (*PubKey) ToPublicKey

func (p *PubKey) ToPublicKey() PublicKey

ToPublicKey returns the public key wrap in PublicKey

func (*PubKey) Verify

func (p *PubKey) Verify(data, sig []byte) (bool, error)

Verify verifies a signature

type PublicKey

type PublicKey [util.Length32]byte

PublicKey represents a 32-byte ED25519 public key

func BytesToPublicKey

func BytesToPublicKey(b []byte) PublicKey

BytesToPublicKey copies b to a PublicKey

func StrToPublicKey

func StrToPublicKey(s string) PublicKey

StrToPublicKey converts a string to a PublicKey

func (PublicKey) Bytes

func (pk PublicKey) Bytes() []byte

Bytes returns a slice of bytes

func (PublicKey) Equal

func (pk PublicKey) Equal(o PublicKey) bool

Equal checks equality between h and o

func (PublicKey) Hex

func (pk PublicKey) Hex() []byte

Hex encodes the bytes to hex

func (PublicKey) HexStr

func (pk PublicKey) HexStr() string

HexStr encodes the bytes to hex, prefixed with 0x

func (PublicKey) IsEmpty

func (pk PublicKey) IsEmpty() bool

IsEmpty checks whether the object is empty (having zero values)

func (PublicKey) MarshalJSON

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

func (PublicKey) MustAddress

func (pk PublicKey) MustAddress() identifier.Address

MustAddress derives an address from the key. Panics on failure.

func (PublicKey) MustAddressRaw added in v0.0.29

func (pk PublicKey) MustAddressRaw() []byte

MustAddressRaw derives a raw address from the key. Panics on failure.

func (PublicKey) MustPushKeyAddress

func (pk PublicKey) MustPushKeyAddress() identifier.Address

MustPushKeyAddress derives a push key address from the key. Panics on failure.

func (PublicKey) String

func (pk PublicKey) String() string

func (PublicKey) ToBytes32

func (pk PublicKey) ToBytes32() util.Bytes32

ToBytes32 convert PublicKey to Bytes32

type PushKey

type PushKey []byte

PushKey represents push key

func (PushKey) MarshalJSON

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

func (PushKey) String

func (p PushKey) String() string

String returns the push key ID as a string

Jump to

Keyboard shortcuts

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