go-pkgs: github.com/iotexproject/go-pkgs/crypto Index | Files

package crypto

import "github.com/iotexproject/go-pkgs/crypto"


Package Files

cryptosort.go key.go merkle.go secp256k1.go


var (
    // ErrInvalidKey is the error that the key format is invalid
    ErrInvalidKey = errors.New("invalid key format")
    // ErrPublicKey indicates the error of public key
    ErrPublicKey = errors.New("invalid public key")
    // ErrPrivateKey indicates the error of private key
    ErrPrivateKey = errors.New("invalid private key")
var (
    // CryptoSeed is a hardcoded seed that will be replaced by a seed produced dynamically.
    CryptoSeed = []byte{0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef}

func Sort Uses

func Sort(hashes [][]byte, nonce uint64)

Sort sorts a given slices of hashes cryptographically using hash function

func SortCandidates Uses

func SortCandidates(candidates []string, epochNum uint64, cryptoSeed []byte)

SortCandidates sorts a given slices of hashes cryptographically using hash function

func StringToPubKeyBytes Uses

func StringToPubKeyBytes(pubKey string) ([]byte, error)

StringToPubKeyBytes converts a string of public key to byte slice

type Merkle Uses

type Merkle struct {
    // contains filtered or unexported fields

Merkle tree struct

func NewMerkleTree Uses

func NewMerkleTree(leaves []hash.Hash256) *Merkle

NewMerkleTree creates a merkle tree given hashed leaves

func (*Merkle) HashTree Uses

func (mk *Merkle) HashTree() hash.Hash256

HashTree calculates the root hash of a merkle tree

type PrivateKey Uses

type PrivateKey interface {
    Bytes() []byte
    HexString() string
    EcdsaPrivateKey() *ecdsa.PrivateKey
    PublicKey() PublicKey
    Sign([]byte) ([]byte, error)

PrivateKey represents a private key

func BytesToPrivateKey Uses

func BytesToPrivateKey(prvKey []byte) (PrivateKey, error)

BytesToPrivateKey converts a byte slice to SECP256K1 PrivateKey

func GenerateKey Uses

func GenerateKey() (PrivateKey, error)

GenerateKey generates a SECP256K1 PrivateKey

func HexStringToPrivateKey Uses

func HexStringToPrivateKey(prvKey string) (PrivateKey, error)

HexStringToPrivateKey decodes a string to SECP256K1 PrivateKey

func KeystoreToPrivateKey Uses

func KeystoreToPrivateKey(account accounts.Account, password string) (PrivateKey, error)

KeystoreToPrivateKey generates PrivateKey from Keystore account

type PublicKey Uses

type PublicKey interface {
    Bytes() []byte
    HexString() string
    EcdsaPublicKey() *ecdsa.PublicKey
    Hash() []byte
    Verify([]byte, []byte) bool

PublicKey represents a public key

func BytesToPublicKey Uses

func BytesToPublicKey(pubKey []byte) (PublicKey, error)

BytesToPublicKey converts a byte slice to SECP256K1 PublicKey

func HexStringToPublicKey Uses

func HexStringToPublicKey(pubKey string) (PublicKey, error)

HexStringToPublicKey decodes a string to SECP256K1 PublicKey

Package crypto imports 11 packages (graph) and is imported by 12 packages. Updated 2019-09-14. Refresh now. Tools for package owners.