crypto

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 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 GenerateKeyPair

func GenerateKeyPair(keyfilepath, passwordFile, privateKeyfile string, outputJSON bool) (*keystore.Key, error)
GenerateKeyPair generates an Ethereum key pair.

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 InspectKeyMoniker

func InspectKeyMoniker(configDir string, moniker string, PasswordFile string, showPrivate bool, outputJSON bool) error

InspectKeyMoniker is a wrapper around InspectKey to add moniker support

func NewKeyPair

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

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

func NewKeyPairFull

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

NewKeyPairFull is a wrapper to GenerateKeyPair 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 UpdateKeys

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

UpdateKeys changes the passphrase on an encrypted keyfile

func UpdateKeysMoniker

func UpdateKeysMoniker(configDir string, moniker string, PasswordFile string, newPasswordFile string) error

UpdateKeysMoniker wraps UpdateKeys adding moniker support

func WrapKey

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

WrapKey Create 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"`
}

We just added the public key as one of the fields in the JSON object because 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