key

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: BSD-3-Clause Imports: 19 Imported by: 3

Documentation

Overview

Package key implements key manager and helper functions.

Index

Constants

View Source
const (
	EwoqPrivateKey = privKeyEncPfx + 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

func GetHRP added in v1.0.0

func GetHRP(networkID uint32) string

func SortTransferableInputsWithSigners

func SortTransferableInputsWithSigners(ins []*avax.TransferableInput, signers [][]ids.ShortID)

SortTransferableInputsWithSigners sorts the inputs and signers based on the input's utxo ID.

This is based off of (generics?): https://github.com/ava-labs/avalanchego/blob/224c9fd23d41839201dd0275ac864a845de6e93e/vms/components/avax/transferables.go#L202

Types

type Key

type Key interface {
	// P returns all formatted P-Chain addresses.
	P() []string
	// C returns the C-Chain address in Ethereum format
	C() string
	// Addresses returns the all raw ids.ShortID address.
	Addresses() []ids.ShortID
	// Match attempts to match a list of addresses up to the provided threshold.
	Match(owners *secp256k1fx.OutputOwners, time uint64) ([]uint32, []ids.ShortID, bool)
	// 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,
		signers [][]ids.ShortID,
	)
	// Sign generates [numSigs] signatures and attaches them to [pTx].
	Sign(pTx *txs.Tx, signers [][]ids.ShortID) 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.MilliAvax" 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 *secp256k1.PrivateKey) 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 LoadEwoq added in v1.3.4

func LoadEwoq(networkID uint32) (*SoftKey, error)

func LoadSoft

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

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

func LoadSoftFromBytes added in v1.3.4

func LoadSoftFromBytes(networkID uint32, kb []byte) (*SoftKey, error)

LoadSoftFromBytes loads the private key from bytes and creates the corresponding SoftKey.

func NewSoft

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

func (*SoftKey) Addresses

func (m *SoftKey) Addresses() []ids.ShortID

func (*SoftKey) C

func (m *SoftKey) C() string

func (*SoftKey) Encode

func (m *SoftKey) Encode() string

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

func (*SoftKey) Key

func (m *SoftKey) Key() *secp256k1.PrivateKey

Returns the private key.

func (*SoftKey) KeyChain

func (m *SoftKey) KeyChain() *secp256k1fx.Keychain

Returns the KeyChain

func (*SoftKey) Match

func (m *SoftKey) Match(owners *secp256k1fx.OutputOwners, time uint64) ([]uint32, []ids.ShortID, bool)

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 *txs.Tx, signers [][]ids.ShortID) error

func (*SoftKey) Spends

func (m *SoftKey) Spends(outputs []*avax.UTXO, opts ...OpOption) (
	totalBalanceToSpend uint64,
	inputs []*avax.TransferableInput,
	signers [][]ids.ShortID,
)

func (*SoftKey) X added in v1.3.4

func (m *SoftKey) X() []string

Jump to

Keyboard shortcuts

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