ethereum

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package ethereum provides cryptographic operations used in go-dvote related to ethereum.

Index

Constants

View Source
const PubKeyLength = 66

PubKeyLength is the size of a Public Key

View Source
const PubKeyLengthUncompressed = 130

PubKeyLengthUncompressed is the size of a uncompressed Public Key

View Source
const SignatureLength = 130

SignatureLength is the size of an ECDSA signature in hexString format

View Source
const SigningPrefix = "\u0019Ethereum Signed Message:\n"

SigningPrefix is the prefix added when hashing

Variables

This section is empty.

Functions

func AddrFromJSONsignature

func AddrFromJSONsignature(msg interface{}, sigHex string) (ethcommon.Address, error)

AddrFromJSONsignature recovers the Ethereum address that created the signature of a JSON message

func AddrFromPublicKey

func AddrFromPublicKey(pubHex string) (ethcommon.Address, error)

AddrFromPublicKey standaolone function to obtain the Ethereum address from a ECDSA public key

func AddrFromSignature

func AddrFromSignature(msg []byte, sigHex string) (ethcommon.Address, error)

AddrFromSignature recovers the Ethereum address that created the signature of a message

func CompressPubKey

func CompressPubKey(pubHexDec string) (string, error)

CompressPubKey returns the compressed public key in hexString format

func DecompressPubKey

func DecompressPubKey(pubHexComp string) (string, error)

DecompressPubKey takes a hexString compressed public key and returns it descompressed

func Hash

func Hash(data []byte) []byte

Hash string data adding Ethereum prefix

func HashRaw

func HashRaw(data []byte) []byte

HashRaw hashes a string with no prefix

func PubKeyFromPrivateKey

func PubKeyFromPrivateKey(privHex string) (string, error)

PubKeyFromPrivateKey returns the hex public key given a hex private key

func PubKeyFromSignature

func PubKeyFromSignature(msg []byte, sigHex string) (string, error)

PubKeyFromSignature recovers the ECDSA public key that created the signature of a message public key is hex encoded

func Verify

func Verify(message []byte, signHex, pubHex string) (bool, error)

Verify standalone function for verify a message

Types

type SignKeys

type SignKeys struct {
	Public     ecdsa.PublicKey
	Private    ecdsa.PrivateKey
	Authorized map[ethcommon.Address]bool
	Lock       sync.RWMutex
}

SignKeys represents an ECDSA pair of keys for signing. Authorized addresses is a list of Ethereum like addresses which are checked on Verify

func NewSignKeys added in v0.5.2

func NewSignKeys() *SignKeys

NewSignKeys creates an ECDSA pair of keys for signing and initializes the map for authorized keys

func (*SignKeys) AddAuthKey

func (k *SignKeys) AddAuthKey(address ethcommon.Address)

AddAuthKey adds a new authorized address key

func (*SignKeys) AddHexKey

func (k *SignKeys) AddHexKey(privHex string) error

AddHexKey imports a private hex key

func (*SignKeys) Address added in v0.5.2

func (k *SignKeys) Address() ethcommon.Address

Address returns the SignKeys ethereum address

func (*SignKeys) AddressString added in v0.5.2

func (k *SignKeys) AddressString() string

AddressString returns the ethereum Address as string

func (*SignKeys) Generate

func (k *SignKeys) Generate() error

Generate generates new keys

func (*SignKeys) HexString

func (k *SignKeys) HexString() (string, string)

HexString returns the public compressed and private keys as hex strings

func (*SignKeys) Sign

func (k *SignKeys) Sign(message []byte) (string, error)

Sign signs a message. Message is a normal string (no HexString nor a Hash)

func (*SignKeys) SignJSON

func (k *SignKeys) SignJSON(message interface{}) (string, error)

SignJSON signs a JSON message. Message is a struct interface

func (*SignKeys) Verify

func (k *SignKeys) Verify(message []byte, signHex string) (bool, error)

Verify verifies a message. Signature is HexString

func (*SignKeys) VerifyJSONsender

func (k *SignKeys) VerifyJSONsender(msg interface{}, sigHex string) (bool, ethcommon.Address, error)

VerifyJSONsender verifies if a JSON message is sent by some Authorized address key

func (*SignKeys) VerifySender

func (k *SignKeys) VerifySender(msg []byte, sigHex string) (bool, ethcommon.Address, error)

VerifySender verifies if a message is sent by some Authorized address key

Jump to

Keyboard shortcuts

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