pseudohsm

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package pseudohsm provides a pseudo HSM for development environments.

Package pseudohsm provides a pseudo HSM for development environments.

Index

Constants

View Source
const (

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

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

EntropyLength random entropy length to generate mnemonics.

Variables

View Source
var (
	ErrDuplicateKeyAlias = errors.New("duplicate key alias")
	ErrXPubFormat        = errors.New("xpub format error")
	ErrLoadKey           = errors.New("key not found or wrong password ")
	ErrDecrypt           = errors.New("could not decrypt key with given passphrase")
	ErrMnemonicLength    = errors.New("mnemonic length error")
)

pre-define errors for supporting bytom errorFormatter

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 AmbiguousKeyError

type AmbiguousKeyError struct {
	Pubkey  string
	Matches []XPub
}

AmbiguousKeyError is returned when attempting to unlock an XPub for which more than one file exists.

func (*AmbiguousKeyError) Error

func (err *AmbiguousKeyError) Error() string

type HSM

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

HSM type for storing pubkey and privatekey

func New

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

New method for HSM struct

func (*HSM) Backup

func (h *HSM) Backup() (*KeyImage, error)

Backup export all the HSM keys into array

func (*HSM) HasAlias

func (h *HSM) HasAlias(alias string) bool

HasAlias check whether the key alias exists

func (*HSM) HasKey

func (h *HSM) HasKey(xprv chainkd.XPrv) bool

HasKey check whether the private key exists

func (*HSM) ImportKeyFromMnemonic

func (h *HSM) ImportKeyFromMnemonic(alias string, auth string, mnemonic string, language string) (*XPub, error)

ImportKeyFromMnemonic produces a xprv from mnemonic and stores it in the db.

func (*HSM) ListKeys

func (h *HSM) ListKeys() []XPub

ListKeys returns a list of all xpubs from the store

func (*HSM) LoadChainKDKey

func (h *HSM) LoadChainKDKey(xpub chainkd.XPub, auth string) (xprv chainkd.XPrv, err error)

LoadChainKDKey get xprv from xpub

func (*HSM) ResetPassword

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

ResetPassword reset passphrase for an existing xpub

func (*HSM) Restore

func (h *HSM) Restore(image *KeyImage) error

Restore import the keyImages into HSM

func (*HSM) UpdateKeyAlias

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

UpdateKeyAlias update key alias

func (*HSM) XCreate

func (h *HSM) XCreate(alias string, auth string, language string) (*XPub, *string, 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 KeyImage

type KeyImage struct {
	XKeys []*encryptedKeyJSON `json:"xkeys"`
}

KeyImage is the struct for hold export key data

type XKey

type XKey struct {
	ID      uuid.UUID
	KeyType string
	Alias   string
	XPrv    chainkd.XPrv
	XPub    chainkd.XPub
}

XKey struct type for keystore file

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"`
	XPub  chainkd.XPub `json:"xpub"`
	File  string       `json:"file"`
}

XPub type for pubkey for anyone can see

Jump to

Keyboard shortcuts

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