mockhsm

package
v0.0.0-...-6d4bf48 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package mockhsm provides a mock HSM for development environments. It is unsafe for use in production.

Index

Constants

This section is empty.

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")
)

Functions

This section is empty.

Types

type HSM

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

func New

func New(db pg.DB) *HSM

func (*HSM) Create

func (h *HSM) Create(ctx context.Context, alias string) (*Pub, error)

Create produces a new random prv and stores it in the db.

func (*HSM) DeleteChainKDKey

func (h *HSM) DeleteChainKDKey(ctx context.Context, xpub chainkd.XPub) error

func (*HSM) GetOrCreate

func (h *HSM) GetOrCreate(ctx context.Context, alias string) (*Pub, bool, error)

GetOrCreate looks for the Ed25519 key with the given alias, generating a new one if it's not found.

func (*HSM) ListKeys

func (h *HSM) ListKeys(ctx context.Context, aliases []string, after string, limit int) ([]*XPub, string, error)

ListKeys returns a list of all xpubs from the db.

func (*HSM) Sign

func (h *HSM) Sign(ctx context.Context, pub ed25519.PublicKey, bh *legacy.BlockHeader) ([]byte, error)

Sign looks up the prv given the pub and signs the given msg.

func (*HSM) XCreate

func (h *HSM) XCreate(ctx context.Context, alias string) (*XPub, error)

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

func (*HSM) XSign

func (h *HSM) XSign(ctx context.Context, xpub chainkd.XPub, path [][]byte, msg []byte) ([]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 Pub

type Pub struct {
	Alias *string           `json:"alias"`
	Pub   ed25519.PublicKey `json:"pub"`
}

type XPub

type XPub struct {
	Alias *string      `json:"alias"`
	XPub  chainkd.XPub `json:"xpub"`
}

Jump to

Keyboard shortcuts

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