keyring

package
v1.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

README

Cosmos SDK / PersistenceCore Keyring Helper

Usage

NewCosmosKeyring(opts ...ConfigOpt) (sdk.AccAddress, keyring.Keyring, error)

Options are:

  • WithKeyringDir option sets keyring path in the filesystem, useful when keyring backend is file.
  • WithKeyringAppName option sets keyring application name (used by Cosmos to separate keyrings)
  • WithKeyringBackend sets the keyring backend. Expected values: test, file, os.
  • WithKeyFrom sets the key name to use for signing. Must exist in the provided keyring.
  • WithKeyPassphrase sets the passphrase for keyring files. The package will fallback to os.Stdin if this option was not provided, but passphrase is required.
  • WithPrivKeyHex allows to specify a private key as plaintext hex. Insecure option, use for testing only. The package will create a virtual keyring holding that key, to meet all the interfaces.
  • WithMnemonic allows to specify a mnemonic pharse as plaintext hex. Insecure option, use for testing only. The package will create a virtual keyring to derive the keys and meet all the interfaces.
  • WithUseLedger sets the option to use hardware wallet, if available on the system.

Testing

go test

Generating a Test Fixture

> cd testdata

> persistenceCore keys --keyring-dir `pwd` --keyring-backend file add test

Passphrase should be test12345678 for this fixture to work.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCosmosKeyringCreationFailed = errors.New("cosmos keyring creation failed")
	ErrCosmosKeyringImportFailed   = errors.New("cosmos keyring unable to import key")
	ErrDeriveFailed                = errors.New("key derivation failed")
	ErrFailedToApplyConfigOption   = errors.New("failed to apply config option")
	ErrFilepathIncorrect           = errors.New("incorrect filepath")
	ErrHexFormatError              = errors.New("hex format error")
	ErrIncompatibleOptionsProvided = errors.New("incompatible keyring options provided")
	ErrInsufficientKeyDetails      = errors.New("insufficient cosmos key details provided")
	ErrKeyIncompatible             = errors.New("provided key is incompatible with requested config")
	ErrKeyRecordNotFound           = errors.New("key record not found")
	ErrPrivkeyConflict             = errors.New("privkey conflict")
	ErrUnexpectedAddress           = errors.New("unexpected address")
)

Functions

func NewCosmosKeyring

func NewCosmosKeyring(cdc codec.Codec, opts ...ConfigOpt) (sdk.AccAddress, cosmkeyring.Keyring, error)

NewCosmosKeyring creates a new keyring from a variety of options. See ConfigOpt and related options.

Types

type Backend

type Backend string

Backend defines a known keyring backend name.

const (
	// BackendTest is a testing backend, no passphrases required.
	BackendTest Backend = "test"
	// BackendFile is a backend where keys are stored as encrypted files.
	BackendFile Backend = "file"
	// BackendOS is a backend where keys are stored in the OS key chain. Platform specific.
	BackendOS Backend = "os"
)

type ConfigOpt

type ConfigOpt func(c *cosmosKeyringConfig) error

ConfigOpt defines a known cosmos keyring option.

func WithKeyFrom

func WithKeyFrom(v string) ConfigOpt

WithKeyFrom sets the key name to use for signing. Must exist in the provided keyring.

func WithKeyPassphrase

func WithKeyPassphrase(v string) ConfigOpt

WithKeyPassphrase sets the passphrase for keyring files. Insecure option, use for testing only. The package will fallback to os.Stdin if this option was not provided, but pass is required.

func WithKeyringAppName

func WithKeyringAppName(v string) ConfigOpt

WithKeyringAppName option sets keyring application name (used by Cosmos to separate keyrings).

func WithKeyringBackend

func WithKeyringBackend(v Backend) ConfigOpt

WithKeyringBackend sets the keyring backend. Expected values: test, file, os.

func WithKeyringDir

func WithKeyringDir(v string) ConfigOpt

WithKeyringDir option sets keyring path in the filesystem, useful when keyring backend is `file`.

func WithMnemonic

func WithMnemonic(v string) ConfigOpt

WithMnemonic allows to specify a mnemonic pharse as plaintext hex. Insecure option, use for testing only. The package will create a virtual keyring to derive the keys and meet all the interfaces.

func WithPrivKeyHex

func WithPrivKeyHex(v string) ConfigOpt

WithPrivKeyHex allows to specify a private key as plaintext hex. Insecure option, use for testing only. The package will create a virtual keyring holding that key, to meet all the interfaces.

func WithUseLedger

func WithUseLedger(b bool) ConfigOpt

WithUseLedger sets the option to use hardware wallet, if available on the system.

Jump to

Keyboard shortcuts

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