crypto

package
v0.0.0-...-9098a98 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package crypto provides some convenient methods to compute hashes and to generate cryptographic keys.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKey = errors.New("invalid key string")
)

Functions

func EncodeKey

func EncodeKey(ultKey *ULTKey) string

Encode UTLKey to base58 encoded key string.

func GetAccountKeypair

func GetAccountKeypair() (string, string, error)

Randomly generate a pair of account public and private key.

func GetAccountKeypairFromSeed

func GetAccountKeypairFromSeed(seed []byte) (string, string, error)

Generate account keypair from provided seed.

func GetNodeKeypair

func GetNodeKeypair() (string, string, error)

Randomly generate a pair of node public and private key.

func GetOfferID

func GetOfferID() (string, error)

Generate random offerID

func IsValidAccountKey

func IsValidAccountKey(key string) bool

Check the validity of supplied acount key string.

func IsValidKey

func IsValidKey(key string) bool

Check the validity of supplied key string.

func IsValidTxKey

func IsValidTxKey(key string) bool

Check the validity of supplied tx key string.

func SHA256Hash

func SHA256Hash(b []byte) string

Compute sha256 checksum (32 bytes) and return a string.

func SHA256HashBytes

func SHA256HashBytes(b []byte) [32]byte

Compute sha256 checksum (32 bytes) and return a byte array.

func SHA256HashUint64

func SHA256HashUint64(b []byte) uint64

Compute sha256 checksum and generate a uint64 number.

func Sign

func Sign(seed string, data []byte) (string, error)

Sign the data with provided seed (equivalent private key).

func Verify

func Verify(publicKey, signature string, data []byte) bool

Verify the data signature with encoded string representation of the public key.

func VerifyByKey

func VerifyByKey(pk *ULTKey, signature string, data []byte) bool

Verify the data signature using ULTKey.

Types

type KeyType

type KeyType uint8
const (
	KeyTypeAccountID KeyType
	KeyTypeSeed
	KeyTypeTx
	KeyTypeTxSet
	KeyTypeNodeID
	KeyTypeLedgerHeader
	KeyTypeOfferID
)

Enumeration of key type.

type ULTKey

type ULTKey struct {
	Code KeyType
	Hash [32]byte
}

ULTKey is the internal key to represent various key hash, Code is for identifying the type of certain key hash.

func DecodeKey

func DecodeKey(key string) (*ULTKey, error)

Decode base58 encoded key string to ULTKey.

Jump to

Keyboard shortcuts

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