utils

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2019 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPoW

func CheckPoW(hash Hash, difficulty int) bool

CheckPoW verifies the PoW difficulty of a Hash

func EthBytesToUint32

func EthBytesToUint32(b []byte) uint32

EthBytesToUint32 converts bytes as big endian to uint32.

func EthBytesToUint64

func EthBytesToUint64(b []byte) uint64

EthBytesToUint64 converts bytes as big endian to uint64.

func GetPkFromKeyStore added in v0.0.3

func GetPkFromKeyStore(ks *keystore.KeyStore, addr common.Address) (*ecdsa.PublicKey, error)

GetPkFromKeyStore is a hack to obtain the public key of an addres who's private key is stored in a key store. It does this by signing an empty hash and recovering the public key from the signature.

func Sign

func Sign(h Hash, ks *keystore.KeyStore, acc accounts.Account) ([]byte, error)

Sign performs the signature over a Hash

func Uint32ToEthBytes

func Uint32ToEthBytes(u uint32) []byte

Uint32ToEthBytes converts a uint32 to bytes in big endian.

func Uint64ToEthBytes

func Uint64ToEthBytes(u uint64) []byte

Uint64ToEthBytes convets a uint64 to bytes in big endian.

func VerifySig

func VerifySig(addr common.Address, sig *Signature, msgHash []byte) bool

VerifySig verifies a given signature and the msgHash with the expected address

func VerifySigEthMsg

func VerifySigEthMsg(addr common.Address, sig *SignatureEthMsg, msg []byte) bool

func VerifySigEthMsgDate

func VerifySigEthMsgDate(addr common.Address, sig *SignatureEthMsg, msg []byte, date int64) bool

VerifySigEthMsgDate verifies the signature of a byte array with a date appended given an ethereum address.

func VerifyTimestamp

func VerifyTimestamp(timestamp int64, timelimit int) bool

Types

type Hash

type Hash [32]byte

Hash used in this tree, is the [32]byte keccak()

func EthHash

func EthHash(b []byte) Hash

EthHash is the hashing function used before signing ethereum messages.

func HashBytes

func HashBytes(b ...[]byte) (hash Hash)

hashBytes performs a Keccak256 hash over the bytes

func (Hash) Hex

func (hash Hash) Hex() string

Hex returns a hex string from the Hash type

type PoWData

type PoWData interface {
	IncrementNonce() PoWData
}

PoWData is the interface for the data that have the Nonce parameter to calculate the Proof-of-Work

func PoW

func PoW(data PoWData, difficulty int) (PoWData, error)

PoW calculates the nonce for the given data in order to fit in the current Proof of Work difficulty

type PublicKey

type PublicKey struct {
	ecdsa.PublicKey
}

PublicKey is a secp256k1 public key used to verify ecdsa signatures.

func (*PublicKey) MarshalJSON

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

MarshalJSON serializes the public key as a hex string.

func (*PublicKey) UnmarshalJSON

func (pk *PublicKey) UnmarshalJSON(bs []byte) error

UnmarshalJSON deserializes the public key from a hex string.

type Signature

type Signature [65]byte

Signature is a secp256k1 ecdsa signature.

func (*Signature) MarshalJSON

func (s *Signature) MarshalJSON() ([]byte, error)

MarshalJSON serializes a signature as a hex string.

func (*Signature) UnmarshalJSON

func (s *Signature) UnmarshalJSON(bs []byte) error

UnmarshalJSON deserializes a signature from a hex string.

type SignatureEthMsg

type SignatureEthMsg [65]byte

SignatureEthMsg is a secp256k1 ecdsa signature of an ethereum message: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sig://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign

func SignEthMsg

func SignEthMsg(ks *keystore.KeyStore, acc accounts.Account, msg []byte) (*SignatureEthMsg, error)

SignEthMsg performs an ethereum message signature over a Hash.

func (*SignatureEthMsg) MarshalJSON

func (s *SignatureEthMsg) MarshalJSON() ([]byte, error)

MarshalJSON serializes a signature as a hex string.

func (*SignatureEthMsg) UnmarshalJSON

func (s *SignatureEthMsg) UnmarshalJSON(bs []byte) error

UnmarshalJSON deserializes a signature from a hex string.

Jump to

Keyboard shortcuts

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