crypto

package
Version: v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

README

crypto GoDoc

iden3 crypto Go package

Cryptography primitives are in https://github.com/iden3/go-iden3-crypto

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPkFromKeyStore

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(hash Hash, ks *keystore.KeyStore, acc accounts.Account) ([]byte, error)

Sign performs the signature over a Hash

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.

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 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