component

package
v0.0.0-...-9faecf3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: LGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// StandardScryptN is the N parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptN = 1 << 18

	// StandardScryptP is the P parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptP = 1

	// LightScryptN is the N parameter of Scrypt encryption algorithm, using 4MB
	// memory and taking approximately 100ms CPU time on a modern processor.
	LightScryptN = 1 << 12

	// LightScryptP is the P parameter of Scrypt encryption algorithm, using 4MB
	// memory and taking approximately 100ms CPU time on a modern processor.
	LightScryptP = 6
)
View Source
const (
	MODULENAME = "accounts"
)

Variables

View Source
var (
	ErrKeyNotExistOrUnlock = errors.New("key not exit or not unlock account")
	ErrKeyNotFound         = errors.New("key not found")
	ErrDecryptFail         = errors.New("decryption failed")
	ErrPassword            = errors.New("password not correct")
	ErrSaveKey             = errors.New("save key failed")
	ErrDecrypt             = errors.New("could not decrypt key with given passphrase")
)

Functions

func BytesToCryptoNode

func BytesToCryptoNode(data []byte, auth string) (node *types.Node, errRef error)

BytesToCryptoNode cocnvert given bytes and password to a node

func DecryptData

func DecryptData(cryptoNode CryptedNode, auth string) ([]byte, error)

Types

type CacheStore

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

accountCache This is used for buffering real storage and upper applications to speed up reading. TODO If the write speed becomes a bottleneck, write caching can be added

func NewCacheStore

func NewCacheStore(keyStore KeyStore, password string) (*CacheStore, error)

NewCacheStore receive an path and password as argument path refer to the file that contain all key password used to decrypto content in key file

func (*CacheStore) ClearKey

func (cacheStore *CacheStore) ClearKey(addr *crypto.CommonAddress)

func (*CacheStore) ExportKey

func (cacheStore *CacheStore) ExportKey(auth string) ([]*types.Node, error)

ExportKey export all key in cache by password

func (*CacheStore) GetKey

func (cacheStore *CacheStore) GetKey(addr *crypto.CommonAddress, auth string) (*types.Node, error)

GetKey Get the private key by address and password Notice if you wallet is locked ,private key cant be found

func (*CacheStore) JoinPath

func (cacheStore *CacheStore) JoinPath(filename string) string

JoinPath refer to local file

func (*CacheStore) ListAddr

func (cacheStore *CacheStore) ListAddr(auth string) ([]string, error)

func (*CacheStore) LoadKeys

func (cacheStore *CacheStore) LoadKeys(addr *crypto.CommonAddress, auth string) error

add private key to buff

func (*CacheStore) StoreKey

func (cacheStore *CacheStore) StoreKey(k *types.Node, auth string) error

StoreKey store key local storage medium

type CipherParams

type CipherParams struct {
	IV []byte `json:"iv"`
}

type CryptedNode

type CryptedNode struct {
	Version int `json:"version"`

	Data []byte `json:"-"`

	CipherText []byte            `json:"cipherText"`
	ChainId    types.ChainIdType `json:"chainId"`
	ChainCode  []byte            `json:"chainCode"`

	Cipher       string       `json:"cipher"`
	CipherParams CipherParams `json:"cipherParams"`

	KDFParams ScryptParams `json:"KDFParams"`
	MAC       []byte       `json:"mac"`
}

func (*CryptedNode) EncryptData

func (node *CryptedNode) EncryptData(auth []byte) error

Encryptdata encrypts the data given as 'data' with the password 'auth'.

type DbStore

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

DbStore use leveldb as the storegae

func NewDbStore

func NewDbStore(dbStoreDir string) *DbStore

func (*DbStore) Close

func (dbStore *DbStore) Close()

func (*DbStore) ExportAddrs

func (dbStore *DbStore) ExportAddrs(auth string) ([]string, error)

func (*DbStore) ExportKey

func (dbStore *DbStore) ExportKey(auth string) ([]*types.Node, error)

ExportKey export all key in db by password

func (*DbStore) GetKey

func (db *DbStore) GetKey(addr *crypto.CommonAddress, auth string) (*types.Node, error)

GetKey read key in db

func (*DbStore) JoinPath

func (dbStore *DbStore) JoinPath(filename string) string

JoinPath return the db file path

func (*DbStore) StoreKey

func (dbStore *DbStore) StoreKey(key *types.Node, auth string) error

store the key in db after encrypto

type FileStore

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

func NewFileStore

func NewFileStore(keyStoreDir string) FileStore

func (FileStore) ExportAddrs

func (fs FileStore) ExportAddrs(auth string) ([]string, error)

func (FileStore) ExportKey

func (fs FileStore) ExportKey(auth string) ([]*types.Node, error)

ExportKey export all key in file by password

func (FileStore) GetKey

func (fs FileStore) GetKey(addr *crypto.CommonAddress, auth string) (*types.Node, error)

GetKey read key in file

func (FileStore) JoinPath

func (fs FileStore) JoinPath(filename string) string

JoinPath return keystore directory

func (FileStore) StoreKey

func (fs FileStore) StoreKey(key *types.Node, auth string) error

store the key in file encrypto

type KeyStore

type KeyStore interface {
	// Loads and decrypts the key from disk.
	GetKey(addr *crypto.CommonAddress, auth string) (*types.Node, error)
	// Writes and encrypts the key.
	StoreKey(k *types.Node, auth string) error
	// Writes and encrypts the key.
	ExportKey(auth string) ([]*types.Node, error)
	// Joins filename with the key directory unless it is already absolute.
	JoinPath(filename string) string

	//export all addresses
	ExportAddrs(auth string) ([]string, error)
}

type MemoryStore

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

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) ExportAddrs

func (mstore *MemoryStore) ExportAddrs(auth string) ([]string, error)

func (*MemoryStore) ExportKey

func (mstore *MemoryStore) ExportKey(auth string) ([]*types.Node, error)

func (*MemoryStore) GetKey

func (mstore *MemoryStore) GetKey(addr *crypto.CommonAddress, auth string) (*types.Node, error)

func (*MemoryStore) JoinPath

func (mstore *MemoryStore) JoinPath(filename string) string

func (*MemoryStore) StoreKey

func (mstore *MemoryStore) StoreKey(k *types.Node, auth string) error

type ScryptParams

type ScryptParams struct {
	N     int    `json:"n"`
	R     int    `json:"r"`
	P     int    `json:"p"`
	Dklen int    `json:"dklen"`
	Salt  []byte `json:"salt"`
}

Jump to

Keyboard shortcuts

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