key

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2022 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package key implements key manager and helper functions.

Index

Constants

View Source
const (
	EwoqPrivateKey = "PrivateKey-" + rawEwoqPk
)

Variables

View Source
var (
	ErrInvalidType = errors.New("invalid type")

	// ErrInvalidPrivateKey is returned when specified privates are invalid.
	ErrInvalidPrivateKey         = errors.New("invalid private key")
	ErrInvalidPrivateKeyLen      = errors.New("invalid private key length (expect 64 bytes in hex)")
	ErrInvalidPrivateKeyEnding   = errors.New("invalid private key ending")
	ErrInvalidPrivateKeyEncoding = errors.New("invalid private key encoding")
)

Functions

This section is empty.

Types

type Addresser

type Addresser interface {
	// P returns the P-Chain address.
	P() string
}

type Key

type Key interface {
	Addresser
	Spender

	// Returns the name of the key.
	Name() string
	// Returns the private key.
	Key() *crypto.PrivateKeySECP256K1R
	// Returns the private key in raw bytes.
	Raw() []byte
	// Returns the private key encoded in CB58 and "PrivateKey-" prefix.
	Encode() string
	// Saves the private key to disk with hex encoding.
	Save(p string) error
}

Key defines methods for key manager interface.

func Load

func Load(networkID uint32, keyPath string) (Key, error)

Loads the private key from disk and creates the corresponding manager.

func New

func New(networkID uint32, name string, opts ...OpOption) (Key, error)

type Op

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

type OpOption

type OpOption func(*Op)

func WithFeeDeduct

func WithFeeDeduct(fee uint64) OpOption

To deduct transfer fee from total spend (output). e.g., "units.MilliAvax" for X/P-Chain transfer.

func WithPrivateKey

func WithPrivateKey(privKey *crypto.PrivateKeySECP256K1R) OpOption

To create a new key manager with a pre-loaded private key.

func WithPrivateKeyEncoded

func WithPrivateKeyEncoded(privKey string) OpOption

To create a new key manager with a pre-defined private key.

func WithTargetAmount

func WithTargetAmount(ta uint64) OpOption

func WithTime

func WithTime(t uint64) OpOption

type Spender

type Spender interface {
	// Spend attempts to spend all specified UTXOs (outputs)
	// and returns the new UTXO inputs.
	// If target amount is specified, it only uses the
	// outputs until the total spending is below the target
	// amount.
	Spends(outputs []*avax.UTXO, opts ...OpOption) (
		totalBalanceToSpend uint64,
		inputs []*avax.TransferableInput,
		inputSigners [][]*crypto.PrivateKeySECP256K1R,
	)
}

Jump to

Keyboard shortcuts

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