crypto

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: LGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAddress

func CreateAddress(addr common.Address, nonce uint64) common.Address

CreateAddress creates a new address with the specified address and nonce. Generally, it's used to create a new contract address based on the account address and nonce. Note, the new created contract address and the account address are in the same shard.

func CreateAddress2

func CreateAddress2(b common.Address, salt common.Hash, inithash []byte) common.Address

CreateAddress2 creates an ethereum address given the address bytes, initial contract code hash and a salt.

func Ecrecover

func Ecrecover(hash, sig []byte) ([]byte, error)

func FromECDSA

func FromECDSA(priv *ecdsa.PrivateKey) []byte

FromECDSA exports a private key into a binary dump.

func FromECDSAPub

func FromECDSAPub(pub *ecdsa.PublicKey) []byte

FromECDSAPub marshals and returns the byte array of the specified ECDSA public key.

func GenerateKey

func GenerateKey() (*ecdsa.PrivateKey, error)

GenerateKey generates and returns an ECDSA private key.

func GenerateKeyPair

func GenerateKeyPair() (*common.Address, *ecdsa.PrivateKey, error)

GenerateKeyPair generates public key and private key

func GenerateRandomAddress

func GenerateRandomAddress() (*common.Address, error)

GenerateRandomAddress generates and returns a random address.

func GetAddress

func GetAddress(key *ecdsa.PublicKey) *common.Address

GetAddress gets an address from the given public key

func HashBytes

func HashBytes(data ...[]byte) common.Hash

HashBytes returns the hash of the input data.

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256 calculates and returns the Keccak256 hash of the input data.

func Keccak256Hash

func Keccak256Hash(data ...[]byte) common.Hash

Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.

func Keccak512

func Keccak512(data ...[]byte) []byte

Keccak512 calculates and returns the Keccak512 hash of the input data.

func LoadECDSAFromString

func LoadECDSAFromString(ecStr string) (*ecdsa.PrivateKey, error)

LoadECDSAFromString creates ecdsa private key from the given string. ecStr should start with 0x or 0X

func MustGenerateKeyPairNotShard

func MustGenerateKeyPairNotShard(shard uint) (*common.Address, *ecdsa.PrivateKey)

MustGenerateKeyPairNotShard generates and returns a random address and key. Panic on any error.

func MustGenerateRandomAddress

func MustGenerateRandomAddress() *common.Address

MustGenerateRandomAddress generates and returns a random address. Panic on any error.

func MustGenerateShardAddress

func MustGenerateShardAddress(shardNum uint) *common.Address

MustGenerateShardAddress generates and returns a random address that match the specified shard number. Panic on any error.

func MustGenerateShardKeyPair

func MustGenerateShardKeyPair(shard uint) (*common.Address, *ecdsa.PrivateKey)

MustGenerateShardKeyPair generates and returns a random address and key. Panic on any error.

func MustHash

func MustHash(v interface{}) common.Hash

MustHash returns the hash of the specified value. Panic on any error, e.g. unsupported data type for encoding.

func PubkeyToAddress

func PubkeyToAddress(key ecdsa.PublicKey) common.Address

PubkeyToAddress add this method for istanbul BFT integration

func PubkeyToString

func PubkeyToString(pub *ecdsa.PublicKey) string

PubkeyToString returns the string of the given public key, with prefix 0x

func S256

func S256() elliptic.Curve

S256 returns an instance of the secp256k1 curve.

func SigToPub

func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)

func ToECDSA

func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)

ToECDSA creates a private key with the given D value.

func ToECDSAPub

func ToECDSAPub(pub []byte) *ecdsa.PublicKey

ToECDSAPub creates ecdsa.PublicKey object by the given byte array. Pubkey length derived from ecdsa is 65, with constant prefix 4 in the first byte. So if pubkey length equals 64, we insert one byte in front

func ValidateSignatureValues

func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool

ValidateSignatureValues verifies whether the signature values are valid with the given chain rules. The v value is assumed to be either 0 or 1.

Types

type Signature

type Signature struct {
	Sig []byte // [R || S || V] format signature in 65 bytes.
}

Signature is a wrapper for the signed message and it is serializable.

func MustSign

func MustSign(privKey *ecdsa.PrivateKey, hash []byte) *Signature

MustSign signs the specified hash with private key and returns a signature. Panic if failed to sign the hash.

func Sign

func Sign(privKey *ecdsa.PrivateKey, buff []byte) (*Signature, error)

Sign signs the specified bytes with private key and returns a signature.

func (Signature) Verify

func (s Signature) Verify(signer common.Address, hash []byte) bool

Verify verifies the signature against the specified hash. Return true if the signature is valid, otherwise false.

Directories

Path Synopsis
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
cloudflare
Package bn256 implements a particular bilinear group at the 128-bit security level.
Package bn256 implements a particular bilinear group at the 128-bit security level.
google
Package bn256 implements a particular bilinear group.
Package bn256 implements a particular bilinear group.
Package secp256k1 wraps the bitcoin secp256k1 C library.
Package secp256k1 wraps the bitcoin secp256k1 C library.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.

Jump to

Keyboard shortcuts

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