Documentation
¶
Overview ¶
Package ethereum provides cryptographic operations used in go-dvote related to ethereum.
Index ¶
- Constants
- func AddrFromPublicKey(pub []byte) (ethcommon.Address, error)
- func AddrFromSignature(message, signature []byte) (ethcommon.Address, error)
- func BuildVocdoniMessage(message []byte) []byte
- func BuildVocdoniTransaction(txData []byte, chainID string) []byte
- func CompressPubKey(pubHexDec string) (string, error)
- func DecompressPubKey(pubComp types.HexBytes) (types.HexBytes, error)
- func Hash(data []byte) []byte
- func HashRaw(data []byte) []byte
- func PubKeyFromPrivateKey(privHex string) (string, error)
- func PubKeyFromSignature(message, signature []byte) ([]byte, error)
- type SignKeys
- func (k *SignKeys) AddAuthKey(address ethcommon.Address)
- func (k *SignKeys) AddHexKey(privHex string) error
- func (k *SignKeys) Address() ethcommon.Address
- func (k *SignKeys) AddressString() string
- func (k *SignKeys) Generate() error
- func (k *SignKeys) HexString() (string, string)
- func (k *SignKeys) PrivateKey() types.HexBytes
- func (k *SignKeys) PublicKey() types.HexBytes
- func (k *SignKeys) SignEthereum(message []byte) ([]byte, error)
- func (k *SignKeys) SignVocdoniMsg(message []byte) ([]byte, error)
- func (k *SignKeys) SignVocdoniTx(txData []byte, chainID string) ([]byte, error)
- func (k *SignKeys) VerifySender(message, signature []byte) (bool, ethcommon.Address, error)
Constants ¶
const PubKeyLengthBytes = 33
PubKeyLengthBytes is the size of a Public Key
const PubKeyLengthBytesUncompressed = 65
PubKeyLengthBytesUncompressed is the size of a uncompressed Public Key
const SignatureLength = ethcrypto.SignatureLength
SignatureLength is the size of an ECDSA signature in hexString format
const SigningPrefix = "\u0019Ethereum Signed Message:\n"
SigningPrefix is the prefix added when hashing
Variables ¶
This section is empty.
Functions ¶
func AddrFromPublicKey ¶
AddrFromPublicKey standaolone function to obtain the Ethereum address from a ECDSA public key
func AddrFromSignature ¶
AddrFromSignature recovers the Ethereum address that created the signature of a message
func BuildVocdoniMessage ¶ added in v1.3.0
BuildVocdoniMessage builds the payload of a vocdoni message ready to be signed
func BuildVocdoniTransaction ¶ added in v1.3.0
BuildVocdoniTransaction builds the payload of a vochain transaction (txData) ready to be signed
func CompressPubKey ¶
CompressPubKey returns the compressed public key in hexString format
func DecompressPubKey ¶
DecompressPubKey takes a compressed public key and returns it descompressed. If already decompressed, returns the same key.
func PubKeyFromPrivateKey ¶
PubKeyFromPrivateKey returns the hex public key given a hex private key
func PubKeyFromSignature ¶
PubKeyFromSignature recovers the ECDSA public key that created the signature of a message public key is hex encoded
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 ¶
func NewSignKeys() *SignKeys
NewSignKeys creates an ECDSA pair of keys for signing and initializes the map for authorized keys
func (*SignKeys) AddAuthKey ¶
AddAuthKey adds a new authorized address key
func (*SignKeys) AddressString ¶
AddressString returns the ethereum Address as string
func (*SignKeys) HexString ¶
HexString returns the public compressed and private keys as hex strings
func (*SignKeys) PrivateKey ¶ added in v1.4.0
PrivateKey returns the private key
func (*SignKeys) SignEthereum ¶ added in v1.3.0
SignEthereum signs a message. Message is a normal string (no HexString nor a Hash)
func (*SignKeys) SignVocdoniMsg ¶ added in v1.3.0
SignVocdoniMsg signs a vocdoni message. Message is the full payload (no HexString nor a Hash)
func (*SignKeys) SignVocdoniTx ¶ added in v1.3.0
SignVocdoniTx signs a vocdoni transaction. TxData is the full transaction payload (no HexString nor a Hash)