Documentation ¶
Overview ¶
Package ethereum provides cryptographic operations used in go-dvote related to ethereum.
Index ¶
- Constants
- func AddrFromBytes(addr []byte) ethcommon.Address
- func AddrFromPublicKey(pub []byte) (ethcommon.Address, error)
- func AddrFromSignature(message, signature []byte) (ethcommon.Address, error)
- func BuildVocdoniMessage(message []byte) []byte
- func BuildVocdoniProtoTxMessage(tx *models.Tx, chainID string, hash []byte) ([]byte, error)
- func BuildVocdoniTransaction(marshaledTx []byte, chainID string) ([]byte, *models.Tx, error)
- 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 Address
- type SignKeys
- func (k *SignKeys) AccountSIK(secret []byte) ([]byte, error)
- func (k *SignKeys) AccountSIKnullifier(electionID, secret []byte) ([]byte, error)
- 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) SIKsignature() ([]byte, error)
- func (k *SignKeys) Sign(txData []byte) ([]byte, error)
- 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 ( // SignatureLength is the size of an ECDSA signature in hexString format SignatureLength = ethcrypto.SignatureLength // PubKeyLengthBytes is the size of a Public Key PubKeyLengthBytes = 33 // PubKeyLengthBytesUncompressed is the size of a uncompressed Public Key PubKeyLengthBytesUncompressed = 65 // SigningPrefix is the prefix added when hashing SigningPrefix = "\u0019Ethereum Signed Message:\n" // DefaultSIKPayload conatains the default seed to sing during // SIK generation DefaultSIKPayload = "vocdoni-sik-payload" )
Variables ¶
This section is empty.
Functions ¶
func AddrFromBytes ¶ added in v1.7.0
AddrFromBytes returns the Ethereum address from a byte array
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 BuildVocdoniProtoTxMessage ¶ added in v1.10.0
BuildVocdoniProtoTxMessage builds the message to be signed for a vocdoni transaction. It takes an optional transaction hash, if it is not provided it will be computed. It returns the payload that needs to be signed.
func BuildVocdoniTransaction ¶ added in v1.3.0
BuildVocdoniTransaction builds the payload for a Vocdoni transaction. It returns the payload that needs to be signed and the unmarshaled transaction struct.
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 NewSignKeysBatch ¶ added in v1.6.0
NewSignKeysBatch creates a set of eth random signing keys
func (*SignKeys) AccountSIK ¶ added in v1.9.0
AccountSIK method generates the Secret Identity Key for the current SignKeys with the signature of the DefaultSIKPayload and the user secret (if it is provided) following the definition:
SIK = poseidon(address, signature, secret)
The secret could be nil.
func (*SignKeys) AccountSIKnullifier ¶ added in v1.9.0
AccountSIKnullifier method composes the nullifier of the current SignKeys for the desired election id and the secret provided.
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) SIKsignature ¶ added in v1.9.0
SIKsignature signs the default vocdoni sik payload. It envolves the SignEthereum method, using the DefaultSIKPayload and discarding the last byte of the signature (used for recovery), different that the same byte of a signature generated with javascript.
func (*SignKeys) Sign ¶
Sign signs a raw message. TxData is the full transaction payload (no HexString nor a Hash)
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)