crypto

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package crypto provides common functions for manipulating and generating keys

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncryptKey

func EncryptKey(key *keystore.Key, auth string, scryptN, scryptP int) ([]byte, error)

EncryptKey encrypts a key using the specified scrypt parameters into a json blob that can be decrypted later on.

func GenerateKeyfile added in v0.3.0

func GenerateKeyfile(keyfilepath, passwordFile, privateKeyfile string, outputJSON bool) (*keystore.Key, error)

GenerateKeyfile generates an Ethereum keyfile and writes it.

keyfilepath: path to write the new keyfile to. passwordFile: plain text file containing the passphrase to use for the

keyfile.

privateKeyfile: the path to an unencrypted private key. If specified, this

function does not generate a new keyfile, it instead
generates a keyfile from the unencrypted private key.

outputJSON: controls whether the output to stdio is in JSON format or not.

The function returns a key object which can be used to retrieve
public or private keys or the address.

func GetPassphrase

func GetPassphrase(passwordFile string, confirmation bool) (string, error)

GetPassphrase obtains a passphrase given by the user. It first checks the --passfile command line flag and ultimately prompts the user for a passphrase.

func GetPrivateKey

func GetPrivateKey(keyfilepath string, PasswordFile string) (*ecdsa.PrivateKey, error)

GetPrivateKey decrypts a keystore and returns the private key

func GetPrivateKeyString

func GetPrivateKeyString(keyfilePath string, passwordFile string) (string, error)

GetPrivateKeyString decrypts a keystore and returns the private key as a string

func InspectKey

func InspectKey(keyfilepath string, PasswordFile string, showPrivate bool, outputJSON bool) error

InspectKey inspects an encrypted keyfile

func InspectKeyByMoniker added in v0.3.0

func InspectKeyByMoniker(keystore string, moniker string, PasswordFile string, showPrivate bool, outputJSON bool) error

InspectKeyByMoniker is a wrapper around InspectKey to add moniker support

func NewKeyfile added in v0.3.0

func NewKeyfile(keystore, moniker, passwordFile string) (*keystore.Key, error)

NewKeyfile is a wrapper to NewKeyfileFull and thus GenerateKeyfile. It does not support setting a private key. Additionally it does not support outputting to JSON format - if required, that can be achieved calling GenerateKeyfile directly.

func NewKeyfileFull added in v0.3.0

func NewKeyfileFull(keystore, moniker, passwordFile string, privateKeyfile string, outputJSON bool) (*keystore.Key, error)

NewKeyfileFull is a wrapper to GenerateKeyfile adding moniker support

func PromptPassphrase

func PromptPassphrase(confirmation bool) (string, error)

PromptPassphrase prompts the user for a passphrase. Set confirmation to true to require the user to confirm the passphrase.

func PublicKeyHexToAddressHex

func PublicKeyHexToAddressHex(publicKey string) (string, error)

PublicKeyHexToAddressHex takes a Hex string public key and returns a hex string Ethereum style address.

func RandomPassphrase

func RandomPassphrase(n int) string

RandomPassphrase generates a random passphrase

func UpdateKey added in v0.3.0

func UpdateKey(keyfilepath string, PasswordFile string, newPasswordFile string) error

UpdateKey changes the passphrase on an encrypted keyfile

func UpdateKeyByMoniker added in v0.3.0

func UpdateKeyByMoniker(keystore, moniker string, passwordFile string, newPasswordFile string) error

UpdateKeyByMoniker wraps UpdateKey adding moniker support

func WrapKey

func WrapKey(privateKey *ecdsa.PrivateKey) *keystore.Key

WrapKey creates the keyfile object with a random UUID. It would be preferable to create the key manually, rather then calling this function, but we cannot use pborman/uuid directly because it is vendored in go-ethereum. That package defines the type of keystore.Key.Id.

Types

type EncryptedKeyJSONMonet

type EncryptedKeyJSONMonet struct {
	Address   string              `json:"address"`
	PublicKey string              `json:"pub"`
	Crypto    keystore.CryptoJSON `json:"crypto"`
	ID        string              `json:"id"`
	Version   int                 `json:"version"`
}

EncryptedKeyJSONMonet is an extension of a regular Ethereum keyfile with an added public key. It makes our lives easier when working with Babble. We could change the Version number, but then other non-monet tools, would not be able to decrypt keys

Jump to

Keyboard shortcuts

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