key

package
v0.0.0-...-3320e36 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: BSD-3-Clause Imports: 21 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")
	ErrCantSpend   = errors.New("can't spend")
)
View Source
var (
	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 HardKey

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

func NewHard

func NewHard(networkID uint32, accountIndex uint32) (*HardKey, error)

func (*HardKey) Address

func (h *HardKey) Address() ids.ShortID

func (*HardKey) Disconnect

func (h *HardKey) Disconnect() error

func (*HardKey) P

func (h *HardKey) P() string

func (*HardKey) Sign

func (h *HardKey) Sign(pTx *platformvm.Tx, sigs int) error

Sign transaction with the ledger private key

This is a slightly modified version of *platformvm.Tx.Sign().

func (*HardKey) Spends

func (h *HardKey) Spends(outputs []*djtx.UTXO, opts ...OpOption) (
	totalBalanceToSpend uint64,
	inputs []*djtx.TransferableInput,
)

type Key

type Key interface {
	// P returns the formatted P-Chain address.
	P() string
	// Address returns the raw ids.ShortID address.
	Address() ids.ShortID
	// 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 []*djtx.UTXO, opts ...OpOption) (
		totalBalanceToSpend uint64,
		inputs []*djtx.TransferableInput,
	)
	// Sign generates [numSigs] signatures and attaches them to [pTx].
	Sign(pTx *platformvm.Tx, numSigs int) error
}

Key defines methods for key manager interface.

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.MilliDjtx" for X/P-Chain transfer.

func WithTargetAmount

func WithTargetAmount(ta uint64) OpOption

func WithTime

func WithTime(t uint64) OpOption

type SOp

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

type SOpOption

type SOpOption func(*SOp)

func WithPrivateKey

func WithPrivateKey(privKey *crypto.PrivateKeySECP256K1R) SOpOption

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

func WithPrivateKeyEncoded

func WithPrivateKeyEncoded(privKey string) SOpOption

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

type SoftKey

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

func LoadSoft

func LoadSoft(networkID uint32, keyPath string) (*SoftKey, error)

LoadSoft loads the private key from disk and creates the corresponding SoftKey.

func NewSoft

func NewSoft(networkID uint32, opts ...SOpOption) (*SoftKey, error)

func (*SoftKey) Address

func (m *SoftKey) Address() ids.ShortID

func (*SoftKey) Encode

func (m *SoftKey) Encode() string

Returns the private key encoded in CB58 and "PrivateKey-" prefix.

func (*SoftKey) Key

Returns the private key.

func (*SoftKey) P

func (m *SoftKey) P() string

func (*SoftKey) Raw

func (m *SoftKey) Raw() []byte

Returns the private key in raw bytes.

func (*SoftKey) Save

func (m *SoftKey) Save(p string) error

Saves the private key to disk with hex encoding.

func (*SoftKey) Sign

func (m *SoftKey) Sign(pTx *platformvm.Tx, sigs int) error

func (*SoftKey) Spends

func (m *SoftKey) Spends(outputs []*djtx.UTXO, opts ...OpOption) (
	totalBalanceToSpend uint64,
	inputs []*djtx.TransferableInput,
)

Jump to

Keyboard shortcuts

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