keystore

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package keystore implements ethereum specific key handling functionality for the node software.

It provides wrapped types and methods for using ethereum keys, keystore and signing.

Index

Constants

This section is empty.

Variables

View Source
var (
	StandardScryptN = ethereumKeystore.StandardScryptN
	StandardScryptP = ethereumKeystore.StandardScryptP
)

Standard parameter values for N,P in Scrypt algorithm used for encrypting keys stored on disk.

Functions

func FromECDSAPub

func FromECDSAPub(pub *ecdsa.PublicKey) []byte

FromECDSAPub returns the byte representation of the ecdsa public key.

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256 computes and returns the Keccak256 hash over the data.

func PubkeyToAddress

func PubkeyToAddress(p ecdsa.PublicKey) types.Address

PubkeyToAddress derives and returns the ethereum specific onchain identity from the ecdsa the public key.

func SetLogger

func SetLogger(moduleLogger log.LoggerInterface)

SetLogger sets the logger instance for this module.

func SigToPub

func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)

SigToPub retrieves and returns the public key that created the given signature.

func VerifySignature

func VerifySignature(pubkey, hash, signature []byte) bool

VerifySignature checks if the given ethereum address created the ecdsa signature over hash. The signature should be of size of 65 byte (in [R | S | V] format with V = 0/1).

Types

type Account

type Account struct {
	accounts.Account
}

Account wraps the Account type defined in go-ethereum/accounts. It consists of onchain address and url to locate the key file in the backend.

func MakeAccount

func MakeAccount(ethAddr types.Address) Account

MakeAccount creates and returns and ethereum account (with empty url) from ethereum onchain id.

type CryptoWrapperInterface

type CryptoWrapperInterface interface {
	SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)
	PubkeyToAddress(p ecdsa.PublicKey) common.Address
	FromECDSAPub(pub *ecdsa.PublicKey) []byte
	VerifySignature(pubkey, hash, signature []byte) bool
	Keccak256(data ...[]byte) []byte
}

CryptoWrapperInterface defines signatures for cryptography related function that will be used to handle ethereum keys.

var CryptoWrapperInstance CryptoWrapperInterface = EthereumCryptoWrapper{}

CryptoWrapperInstance defines the crypto wrapper instance that can be used by other modules.

type EthereumCryptoWrapper

type EthereumCryptoWrapper struct {
}

EthereumCryptoWrapper wraps the ethereum specific crypto related functions.

func (EthereumCryptoWrapper) FromECDSAPub

func (wrapper EthereumCryptoWrapper) FromECDSAPub(pub *ecdsa.PublicKey) []byte

FromECDSAPub wraps the FromECDSAPub function from ethereum/crypto package.

func (EthereumCryptoWrapper) Keccak256

func (wrapper EthereumCryptoWrapper) Keccak256(data ...[]byte) []byte

Keccak256 wraps the Keccak256 function from ethereum/crypto package.

func (EthereumCryptoWrapper) PubkeyToAddress

func (wrapper EthereumCryptoWrapper) PubkeyToAddress(p ecdsa.PublicKey) common.Address

PubkeyToAddress wraps the PubkeyToAddress function from ethereum/crypto package.

func (EthereumCryptoWrapper) SigToPub

func (wrapper EthereumCryptoWrapper) SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)

SigToPub wraps the SigToPub function from ethereum/crypto package.

func (EthereumCryptoWrapper) VerifySignature

func (wrapper EthereumCryptoWrapper) VerifySignature(pubkey, hash, signature []byte) bool

VerifySignature wraps the VerifySignature function from ethereum/crypto package.

type Key

type Key struct {
	*ethereumKeystore.Key
}

Key wraps the Key type from ethereumKeystore. It stores the private key in plain text and ethereum address corresponding to it.

type KeyStore

type KeyStore struct {
	*ethereumKeystore.KeyStore
}

KeyStore wraps the ethereum keystore that is used to manage a keys storage directory on disk.

func NewKeyStore

func NewKeyStore(keysDir string, scryptN, scryptP int) *KeyStore

NewKeyStore initializes and returns an new instance of ethereum keystore.

func (*KeyStore) Find

func (ks *KeyStore) Find(a Account) (Account, error)

Find retrieves and returns an unique account corresponding to the ethereum address from the keystore. If no account or multiple matching accounts are found, an error is returned.

func (*KeyStore) GetKey

func (ks *KeyStore) GetKey(ethAddr types.Address, password string) (
	*Key, error)

GetKey returns the decrypted private key corresponding to the ethereum address if the password is correct. In case the password is wrong or key not found in keystore, an error is returned.

func (*KeyStore) SignHashWithPassphrase

func (ks *KeyStore) SignHashWithPassphrase(a Account, passphrase string, hash []byte) (signature []byte, err error)

SignHashWithPassphrase generates a signatures over the hash, provided correct passphrase is provided.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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