Documentation
¶
Overview ¶
Package key provides hierarchical deterministic key derivation for all key types used in the Lux network: secp256k1 (EC), BLS, Ringtail, and ML-DSA.
Package key implements key manager and helper functions.
Index ¶
- Constants
- Variables
- func DeleteKeySet(name string) error
- func GenerateMnemonic() (string, error)
- func GetHRP(networkID uint32) string
- func GetKeysDir() (string, error)
- func GetLocalKeyPath() string
- func GetLocalPrivateKey() (*secp256k1.PrivateKey, error)
- func ListKeySets() ([]string, error)
- func SaveKeySet(keySet *HDKeySet) error
- func SortTransferableInputsWithSigners(ins []*lux.TransferableInput, signers [][]ids.ShortID)
- func ValidateMnemonic(mnemonic string) bool
- type HDKeySet
- type Key
- type Op
- type OpOption
- type SOp
- type SOpOption
- type SoftKey
- func (m *SoftKey) Addresses() []ids.ShortID
- func (m *SoftKey) C() string
- func (m *SoftKey) Encode() string
- func (m *SoftKey) Key() *secp256k1.PrivateKey
- func (m *SoftKey) KeyChain() *secp256k1fx.Keychain
- func (m *SoftKey) Match(owners *secp256k1fx.OutputOwners, time uint64) ([]uint32, []ids.ShortID, bool)
- func (m *SoftKey) P() []string
- func (m *SoftKey) PrivKeyHex() string
- func (m *SoftKey) PrivateKeyRaw() string
- func (m *SoftKey) Raw() []byte
- func (m *SoftKey) Save(p string) error
- func (m *SoftKey) Sign(pTx *txs.Tx, signers [][]ids.ShortID) error
- func (m *SoftKey) Spends(outputs []*lux.UTXO, opts ...OpOption) (totalBalanceToSpend uint64, inputs []*lux.TransferableInput, ...)
- func (m *SoftKey) X() []string
Constants ¶
const ( // Key type subdirectories ECKeyDir = "ec" // secp256k1 keys for transaction signing BLSKeyDir = "bls" // BLS keys for consensus RingtailKeyDir = "rt" // Ringtail keys for ring signatures MLDSAKeyDir = "mldsa" // ML-DSA keys for post-quantum signatures // Key file names PrivateKeyFile = "private.key" PublicKeyFile = "public.key" MnemonicFile = "mnemonic.txt" // Domain separation strings for HKDF DomainEC = "lux-ec-key" DomainBLS = "lux-bls-key" DomainRingtail = "lux-ringtail-key" DomainMLDSA = "lux-mldsa-key" )
const ( // LocalKeyName is the name of the local development key file LocalKeyName = "local-key" // LocalKeyPath is the path where the local key is stored LocalKeyPath = "~/.lux/keys/" + LocalKeyName + ".pk" EwoqPrivateKey = privKeyEncPfx + rawEwoqPk )
Variables ¶
var ( ErrInvalidType = errors.New("invalid type") ErrCantSpend = errors.New("can't spend") )
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 DeleteKeySet ¶ added in v1.9.11
DeleteKeySet removes a key set from the filesystem
func GenerateMnemonic ¶ added in v1.9.11
GenerateMnemonic generates a new BIP39 mnemonic phrase
func GetKeysDir ¶ added in v1.9.11
GetKeysDir returns the base directory for all keys
func GetLocalKeyPath ¶ added in v1.9.8
func GetLocalKeyPath() string
GetLocalKeyPath returns the expanded path to the local key file
func GetLocalPrivateKey ¶ added in v1.9.8
func GetLocalPrivateKey() (*secp256k1.PrivateKey, error)
GetLocalPrivateKey returns the secp256k1 private key for local development. It loads from ~/.lux/keys/local-key.pk, generating a new key if needed.
func ListKeySets ¶ added in v1.9.11
ListKeySets lists all available key sets
func SaveKeySet ¶ added in v1.9.11
SaveKeySet saves all keys to the filesystem in organized subdirectories Structure: ~/.lux/keys/<name>/{ec,bls,rt,mldsa}/{private.key,public.key}
func SortTransferableInputsWithSigners ¶
func SortTransferableInputsWithSigners(ins []*lux.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/luxfi/node/blob/224c9fd23d41839201dd0275ac864a845de6e93e/vms/components/lux/transferables.go#L202
func ValidateMnemonic ¶ added in v1.9.11
ValidateMnemonic validates a BIP39 mnemonic phrase
Types ¶
type HDKeySet ¶ added in v1.9.11
type HDKeySet struct {
Name string
Mnemonic string
// secp256k1 (EC) keys
ECPrivateKey []byte
ECPublicKey []byte
ECAddress string // Ethereum-style address (0x...)
// BLS keys
BLSPrivateKey []byte
BLSPublicKey []byte
BLSPoP []byte
// Ringtail keys
RingtailPrivateKey []byte
RingtailPublicKey []byte
// ML-DSA keys
MLDSAPrivateKey []byte
MLDSAPublicKey []byte
}
HDKeySet represents a complete set of keys derived from a single seed
func DeriveAllKeys ¶ added in v1.9.11
DeriveAllKeys derives all key types from a mnemonic phrase
func LoadKeySet ¶ added in v1.9.11
LoadKeySet loads all keys from the filesystem
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 []*lux.UTXO, opts ...OpOption) (
totalBalanceToSpend uint64,
inputs []*lux.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 OpOption ¶
type OpOption func(*Op)
func WithFeeDeduct ¶
To deduct transfer fee from total spend (output). e.g., "units.MilliLux" for X/P-Chain transfer.
func WithTargetAmount ¶
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 ¶
To create a new key SoftKey with a pre-defined private key.
type SoftKey ¶
type SoftKey struct {
// contains filtered or unexported fields
}
func GetOrCreateLocalKey ¶ added in v1.9.8
GetOrCreateLocalKey loads the local development key from ~/.lux/keys/local-key.pk, generating a new one if it doesn't exist. This is the secure replacement for the hardcoded EWOQ key.
func (*SoftKey) Match ¶
func (m *SoftKey) Match(owners *secp256k1fx.OutputOwners, time uint64) ([]uint32, []ids.ShortID, bool)
func (*SoftKey) PrivKeyHex ¶
func (*SoftKey) PrivateKeyRaw ¶
PrivateKeyRaw returns the private key in hex format