pseudohsm

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2017 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package pseudohsm provides a pseudo HSM for development environments.

Index

Constants

View Source
const (

	// n,r,p = 2^18, 8, 1 uses 256MB memory and approx 1s CPU time on a modern CPU.
	StandardScryptN = 1 << 18
	StandardScryptP = 1

	// n,r,p = 2^12, 8, 6 uses 4MB memory and approx 100ms CPU time on a modern CPU.
	LightScryptN = 1 << 12
	LightScryptP = 6
)

Variables

View Source
var (
	ErrDuplicateKeyAlias    = errors.New("duplicate key alias")
	ErrInvalidAfter         = errors.New("invalid after")
	ErrNoKey                = errors.New("key not found")
	ErrInvalidKeySize       = errors.New("key invalid size")
	ErrTooManyAliasesToList = errors.New("requested aliases exceeds limit")
	ErrAmbiguousAddr        = errors.New("multiple keys match address")
	ErrDecrypt              = errors.New("could not decrypt key with given passphrase")
	ErrInvalidKeyType       = errors.New("key type stored invalid")
)

Functions

func EncryptKey

func EncryptKey(key *XKey, 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.

Types

type AmbiguousAddrError

type AmbiguousAddrError struct {
	Addr    common.Address
	Matches []XPub
}

AmbiguousAddrError is returned when attempting to unlock an address for which more than one file exists.

func (*AmbiguousAddrError) Error

func (err *AmbiguousAddrError) Error() string

type HSM

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

func New

func New(keypath string) (*HSM, error)

func (*HSM) ListKeys

func (h *HSM) ListKeys(after string, limit int) ([]XPub, string, error)

ListKeys returns a list of all xpubs from the store

func (*HSM) ResetPassword

func (h *HSM) ResetPassword(xpub chainkd.XPub, auth, newAuth string) error

Update changes the passphrase of an existing xpub

func (*HSM) UpdateAlias

func (h *HSM) UpdateAlias(xpub chainkd.XPub, auth, newAlias string) error

Update alias of an existing xpub

func (*HSM) XCreate

func (h *HSM) XCreate(auth string, alias string) (*XPub, error)

XCreate produces a new random xprv and stores it in the db.

func (*HSM) XDelete

func (h *HSM) XDelete(xpub chainkd.XPub, auth string) error

XDelete deletes the key matched by xpub if the passphrase is correct. If a contains no filename, the address must match a unique key.

func (*HSM) XSign

func (h *HSM) XSign(xpub chainkd.XPub, path [][]byte, msg []byte, auth string) ([]byte, error)

XSign looks up the xprv given the xpub, optionally derives a new xprv with the given path (but does not store the new xprv), and signs the given msg.

type XKey

type XKey struct {
	Id      uuid.UUID
	KeyType string
	Alias   string
	Address common.Address
	XPrv    chainkd.XPrv
	XPub    chainkd.XPub
}

func DecryptKey

func DecryptKey(keyjson []byte, auth string) (*XKey, error)

DecryptKey decrypts a key from a json blob, returning the private key itself.

type XPub

type XPub struct {
	Alias   string         `json:"alias"`
	Address common.Address `json:"address"`
	XPub    chainkd.XPub   `json:"xpub"`
	File    string         `json:"file"`
}

Jump to

Keyboard shortcuts

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