crypto

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: Apache-2.0, MIT Imports: 10 Imported by: 1

Documentation

Overview

Package crypto contains types and functions for creating Ethereum private keys and accounts, and creating/recovering signatures made with such keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratePrivateKeyAndAddress

func GeneratePrivateKeyAndAddress() (types.Bytes, types.Address)

GeneratePrivateKeyAndAddress generates a pseudo-random ECDSA secret key and its corresponding Ethereum address.

func GetAddressFromSecretKeyBytes

func GetAddressFromSecretKeyBytes(secretKeyBytes []byte) types.Address

GetAddressFromSecretKeyBytes computes the Ethereum address corresponding to the supplied private key.

func RecoverEthereumMessageSigner

func RecoverEthereumMessageSigner(message []byte, signature Signature) (common.Address, error)

RecoverEthereumMessageSigner accepts a message (bytestring) and signature generated by SignEthereumMessage. It reconstructs the appropriate digest and recovers an address via secp256k1 public key recovery

Types

type Signature

type Signature struct {
	R []byte
	S []byte
	V byte
}

Signature is an ECDSA signature

func SignEthereumMessage

func SignEthereumMessage(message []byte, secretKey []byte) (Signature, error)

SignEthereumMessage accepts an arbitrary message, prepends a known message, hashes the result using keccak256 and calculates the secp256k1 signature of the hash using the provided secret key. The known message added to the input before hashing is "\x19Ethereum Signed Message:\n" + len(message). See https://github.com/ethereum/go-ethereum/pull/2940 and EIPs 191, 721.

func SplitSignature

func SplitSignature(concatenatedSignature []byte) (signature Signature)

splitSignature takes a 65 bytes signature in the [R||S||V] format and returns the individual components

func (Signature) Equal

func (s1 Signature) Equal(s2 Signature) bool

func (Signature) MarshalJSON

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

func (Signature) ToHexString

func (s Signature) ToHexString() string

ToHexString returns the signature as a hex string

func (*Signature) UnmarshalJSON

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

Jump to

Keyboard shortcuts

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