eth

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

The eth package provides wrappers and functionality common to all Ethereum development.

Index

Constants

View Source
const DefaultHDPathPrefix = HDPathPrefix("m/44'/60'/0'/0/")

DefaultHDPathPrefix is the default format for derived accounts when using SignerFromSeedPhrase().

View Source
const Symbol = `Ξ`

Symbol is the ETH symbol.

Variables

This section is empty.

Functions

func Ether

func Ether(e int64) *big.Int

Ether returns e in Wei.

func EtherFraction

func EtherFraction(numerator, denominator int64) *big.Int

EtherFraction returns numerator/denominator ETH in Wei.

func NewMnemonic

func NewMnemonic(bitSize int) (string, error)

NewMnemonic is a convenience wrapper around go-bip39 entropy and mnemonic creation.

func WithPersonalMessagePrefix added in v0.19.0

func WithPersonalMessagePrefix(message []byte) []byte

WithPersonalMessagePrefix converts a given message to conform to the signed data standard according to EIP-191.

Types

type HDPathPrefix

type HDPathPrefix string

An HDPathPrefix is a prefix for use in deriving private keys from BIP39 mnemonics. It is appended with the account number. Values MUST include a trailing slash.

func (HDPathPrefix) SignerFromPRF added in v0.21.0

func (hdp HDPathPrefix) SignerFromPRF(src prf.PRF, input []byte, account uint) (*Signer, error)

SignerFromPRF deterministically derives a private key from the pseudo-random function and the input bytes. By definition, the output of a PRF is indistinguishable from a random function.

The input parameter allows for different sets of HD wallets to be derived from the same underlying PRF key. Only the PRF key need be secret.

SignerFromPRF can be thought of as a method for securely creating new mnemonic seed phrases from a single underlying key and different input parameters. Although the resulting mnemonic is accessible, SignerFromPRF is intended for use in an automated environment, which is why it relies on Google Tink.

func (HDPathPrefix) SignerFromPRFSet added in v0.21.0

func (hdp HDPathPrefix) SignerFromPRFSet(set *prf.Set, input []byte, account uint) (*Signer, error)

SignerFromPRFSet returns hdp.SifnerFromPRF() using the set's primary PRF. This is simply a convenience function as the prf package doesn't accomodate direct creation of a prf.PRF.

func (HDPathPrefix) SignerFromSeedPhrase

func (hdp HDPathPrefix) SignerFromSeedPhrase(mnemonic, password string, account uint) (*Signer, error)

SignerFromSeedPhrase confirms that the mnemonic is valid under BIP39 and then uses it to derive a private key (see HDPathF)

type Signer

type Signer struct {
	// contains filtered or unexported fields
}

A Signer abstracts signing of arbitrary messages by wrapping an ECDSA private key and, optionally, its associated BIP39 mnemonic.

func NewSigner

func NewSigner(bitSize int) (*Signer, error)

NewSigner is equivalent to DefaultHDPathPrefix.SignerFromSeedPhrase(NewMnemonic(), "", 0).

func (*Signer) Address

func (s *Signer) Address() common.Address

Address returns the Signer's public key converted to an Ethereum address.

func (*Signer) Mnemonic

func (s *Signer) Mnemonic() string

Mnemonic returns the mnemonic used to derive the Signer's private key. USE WITH CAUTION.

func (*Signer) PersonalSign added in v0.19.0

func (s *Signer) PersonalSign(buf []byte) ([]byte, error)

PersonalSign returns an EIP-191 conform personal ECDSA signature of buf Convenience wrapper for s.CompactSign(WithPersonalMessagePrefix(buf))

func (*Signer) PersonalSignAddress added in v0.19.0

func (s *Signer) PersonalSignAddress(addr common.Address) ([]byte, error)

SignAddress is a convenience wrapper for s.PersonalSign(addr.Bytes()).

func (*Signer) PersonalSignWithNonce added in v0.19.0

func (s *Signer) PersonalSignWithNonce(buf []byte) ([]byte, [32]byte, error)

PersonalSignWithNonce generates a 32-byte nonce with crypto/rand and returns s.PersonalSign(append(buf, nonce)).

func (*Signer) RawSign

func (s *Signer) RawSign(buf []byte) ([]byte, error)

RawSign returns an ECDSA signature of buf. USE WITH CAUTION as signed data SHOULD be hashed first to avoid chosen-plaintext attacks. Prefer Signer.Sign().

func (*Signer) Sign

func (s *Signer) Sign(buf []byte) ([]byte, error)

Sign returns an ECDSA signature of keccak256(buf).

func (*Signer) String

func (s *Signer) String() string

String returns s.Address() as a string.

func (*Signer) TransactorWithChainID added in v0.29.0

func (s *Signer) TransactorWithChainID(chainID *big.Int) (*bind.TransactOpts, error)

TransactorWithChainID returns bind.NewKeyedTransactorWithChainID(<key>, chainID) where <key> is the Signer's private key.

Jump to

Keyboard shortcuts

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