wallet

package
v1.17.8 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

README

Lux SDK Wallet

Unified wallet implementation for all Lux chains (P, X, C, EVM) with support for both classical and post-quantum cryptography.

Architecture

wallet/
├── crypto/              # Cryptography abstraction layer
│   ├── interface.go     # Unified Signer interface
│   ├── classic/         # Classic crypto (secp256k1, BLS)
│   └── pqc/            # Post-quantum crypto (ML-DSA, ML-KEM, SLH-DSA)
├── chain/              # Chain-specific implementations
│   ├── p/              # P-Chain (Platform) wallet
│   ├── x/              # X-Chain (Exchange) wallet
│   ├── c/              # C-Chain (Contract) wallet
│   └── evm/            # Generic EVM wallet (for L1 chains like Zoo)
└── primary/            # Unified wallet managing all chains

Supported Cryptography

Classic Cryptography
  • SECP256K1 - Ethereum-compatible elliptic curve
  • SECP256R1 - NIST P-256
  • BLS - BLS12-381 for aggregated signatures
Post-Quantum Cryptography (NIST Standards)
  • ML-DSA (Dilithium replacement)
    • ML-DSA-87 (high security)
    • ML-DSA-65 (medium security)
    • ML-DSA-44 (low security)
  • SLH-DSA (SPHINCS+ replacement)
    • SLH-DSA-256
    • SLH-DSA-192
    • SLH-DSA-128
  • ML-KEM (Kyber replacement) - For key encapsulation
Hybrid Schemes
  • SECP256K1 + ML-DSA-87 - Classic + PQC
  • BLS + ML-DSA-87 - Aggregatable + PQC

Usage

Basic Wallet Creation
import (
    "github.com/luxfi/sdk/wallet"
    "github.com/luxfi/sdk/wallet/crypto"
)

// Create wallet with classic crypto
factory := crypto.NewFactory()
signer, err := factory.NewSigner(crypto.SECP256K1, privateKey)

// Create wallet with post-quantum crypto
pqcSigner, err := factory.NewSigner(crypto.MLDSA87, privateKey)

// Create multi-chain wallet
w, err := wallet.NewPrimary(uri, signer)
Chain-Specific Operations
// P-Chain operations
pWallet := w.P()
tx, err := pWallet.IssueAddValidatorTx(...)

// X-Chain operations
xWallet := w.X()
tx, err := xWallet.IssueBaseTx(...)

// C-Chain operations
cWallet := w.C()
tx, err := cWallet.IssueImportTx(...)

// EVM operations (Zoo, etc.)
evmWallet := w.EVM(chainID)
tx, err := evmWallet.SendTransaction(...)

Post-Quantum Migration

All wallet operations support PQC transparently:

// Same API, different crypto
classicSigner := crypto.NewSigner(crypto.SECP256K1, key)
pqcSigner := crypto.NewSigner(crypto.MLDSA87, pqKey)

// Both work with same wallet interface
wallet1 := wallet.New(uri, classicSigner)
wallet2 := wallet.New(uri, pqcSigner)

Features

  • ✅ Unified interface across all chains
  • ✅ Classic and PQC crypto support
  • ✅ Hardware wallet compatibility
  • ✅ BIP32/BIP44 key derivation
  • ✅ Address format compatibility
  • ✅ Cross-chain operations
  • ✅ Atomic swaps between chains
  • ✅ Fee estimation
  • ✅ Transaction building and signing

Documentation

Overview

Package wallet provides multi-chain wallet implementation.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInsufficientFunds = errors.New("insufficient funds")
	ErrNoUTXOs           = errors.New("no UTXOs available")
	ErrInvalidAddress    = errors.New("invalid address")
)
View Source
var ErrAccountNotFound = errors.New("wallet: account not found")

ErrAccountNotFound is returned by PQWallet.SignTx when the supplied AccountID is not in the wallet.

Functions

This section is empty.

Types

type PQWallet added in v1.17.0

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

PQWallet is the post-quantum native wallet facade. It stores PQAccounts (ML-DSA-65) and RecoveryAccounts (SLH-DSA-SHAKE-192s) by their canonical 48-byte AccountID, exposes Sign on accounts by ID, and is safe for concurrent use across goroutines.

PQWallet is intentionally separate from the secp256k1 Wallet type in this package: classical-compat keys live in a strictly disjoint keyring so a chain that refuses WalletSchemeSecp256k1 cannot accidentally see one. Callers that mix classical and PQ keys hold both Wallet and PQWallet instances.

func NewPQWallet added in v1.17.0

func NewPQWallet() *PQWallet

NewPQWallet returns an empty PQWallet. The wallet is in-memory only; persistence is the caller's responsibility (typically through account.SealPQAccount + a file/keychain store).

func (*PQWallet) Account added in v1.17.0

func (w *PQWallet) Account(id account.AccountID) (*account.PQAccount, bool)

Account returns the PQ account with the given AccountID. The second return value is false if no such account is present.

func (*PQWallet) AccountIDs added in v1.17.0

func (w *PQWallet) AccountIDs() []account.AccountID

AccountIDs returns a slice of all hot (PQ) AccountIDs known to the wallet. Order is not stable across calls.

func (*PQWallet) AddAccount added in v1.17.0

func (w *PQWallet) AddAccount(a *account.PQAccount) error

AddAccount inserts a PQ account into the wallet. Returns an error if an account with the same AccountID is already present (idempotent inserts are NOT allowed — callers must choose to overwrite by calling RemoveAccount first).

func (*PQWallet) AddRecovery added in v1.17.0

func (w *PQWallet) AddRecovery(r *account.RecoveryAccount) error

AddRecovery inserts an SLH-DSA recovery account into the wallet.

func (*PQWallet) Recovery added in v1.17.0

func (w *PQWallet) Recovery(id account.AccountID) (*account.RecoveryAccount, bool)

Recovery returns the SLH-DSA recovery account with the given AccountID.

func (*PQWallet) RemoveAccount added in v1.17.0

func (w *PQWallet) RemoveAccount(id account.AccountID) bool

RemoveAccount removes the account with the given AccountID. Returns false if no such account was present.

func (*PQWallet) SignTx added in v1.17.0

SignTx signs the envelope under the account identified by id. Thin wrapper around account.SignTx; returns ErrAccountNotFound if no such account exists. Mirrors the existing Wallet.Sign shape for callers who treat the wallet as the single signing entry point.

type TransferInput

type TransferInput struct {
	UTXOID  ids.ID
	AssetID ids.ID
	Amount  uint64
}

TransferInput represents an input to a transfer transaction

type TransferOutput

type TransferOutput struct {
	AssetID   ids.ID
	Amount    uint64
	Recipient ids.ShortID
	Locktime  uint64
}

TransferOutput represents an output from a transfer transaction

type TransferTx

type TransferTx struct {
	NetworkID uint32
	ChainID   ids.ID
	Inputs    []TransferInput
	Outputs   []TransferOutput
	Memo      []byte
}

TransferTx represents a transfer transaction

type UTXO

type UTXO struct {
	ID       ids.ID
	AssetID  ids.ID
	Amount   uint64
	Owner    ids.ShortID
	Locktime uint64
}

UTXO represents an unspent transaction output

type Wallet

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

Wallet manages keys and transactions for personal usage

func New

func New(networkID uint32, chainID ids.ID) *Wallet

New creates a new wallet instance

func (*Wallet) AddUTXO

func (w *Wallet) AddUTXO(utxo *UTXO)

AddUTXO adds a UTXO to the wallet

func (*Wallet) CreateTransferTx

func (w *Wallet) CreateTransferTx(
	to ids.ShortID,
	assetID ids.ID,
	amount uint64,
	memo []byte,
) (*TransferTx, error)

CreateTransferTx creates a transfer transaction

func (*Wallet) GenerateKey

func (w *Wallet) GenerateKey() (ids.ShortID, error)

GenerateKey generates a new key and adds it to the wallet

func (*Wallet) GetAddress

func (w *Wallet) GetAddress() (ids.ShortID, error)

GetAddress returns a wallet address

func (*Wallet) GetAllAddresses

func (w *Wallet) GetAllAddresses() []ids.ShortID

GetAllAddresses returns all wallet addresses

func (*Wallet) GetBLSKey

func (w *Wallet) GetBLSKey() (*bls.SecretKey, error)

GetBLSKey returns the BLS key for validator operations

func (*Wallet) GetBalance

func (w *Wallet) GetBalance(assetID ids.ID) uint64

GetBalance returns the balance for a specific asset

func (*Wallet) GetUTXOs

func (w *Wallet) GetUTXOs(assetID ids.ID, amount uint64) ([]*UTXO, uint64, error)

GetUTXOs returns UTXOs for spending

func (*Wallet) ImportKey

func (w *Wallet) ImportKey(privateKey crypto.PrivateKey) (ids.ShortID, error)

ImportKey imports a private key into the wallet

func (*Wallet) RemoveUTXO

func (w *Wallet) RemoveUTXO(utxoID ids.ID)

RemoveUTXO removes a UTXO from the wallet

func (*Wallet) SetBLSKey

func (w *Wallet) SetBLSKey(key *bls.SecretKey)

SetBLSKey sets the BLS key for validator operations

func (*Wallet) Sign

func (w *Wallet) Sign(ctx context.Context, tx chain.Transaction) error

Sign signs a transaction with the wallet's keys

Directories

Path Synopsis
Package account implements PQ-native wallet account types.
Package account implements PQ-native wallet account types.
chain
c
Package c provides C-Chain wallet backend implementation.
Package c provides C-Chain wallet backend implementation.
p
Package p provides P-Chain wallet backend implementation.
Package p provides P-Chain wallet backend implementation.
p/builder
Package builder provides P-Chain transaction builder implementation.
Package builder provides P-Chain transaction builder implementation.
p/pcodecs
Package pcodecs is the canonical construction site for the proto/p wire codecs used by the SDK's PVM wallet stack.
Package pcodecs is the canonical construction site for the proto/p wire codecs used by the SDK's PVM wallet stack.
p/signer
Package signer provides P-Chain transaction signing implementation.
Package signer provides P-Chain transaction signing implementation.
p/wallet
Package wallet provides P-Chain wallet implementation.
Package wallet provides P-Chain wallet implementation.
x
Package x provides X-Chain wallet backend implementation.
Package x provides X-Chain wallet backend implementation.
x/builder
Package builder provides X-Chain transaction builder implementation.
Package builder provides X-Chain transaction builder implementation.
x/signer
Package signer provides X-Chain transaction signing implementation.
Package signer provides X-Chain transaction signing implementation.
Package crypto provides cryptographic interfaces for wallet signing.
Package crypto provides cryptographic interfaces for wallet signing.
classic
Package classic provides classic cryptographic signing implementation.
Package classic provides classic cryptographic signing implementation.
pqc
Package pqc provides post-quantum cryptography signing implementation.
Package pqc provides post-quantum cryptography signing implementation.
Package primary provides primary network wallet operations.
Package primary provides primary network wallet operations.
common
Package common provides common wallet utilities.
Package common provides common wallet utilities.
common/utxotest
Package utxotest provides UTXO testing utilities.
Package utxotest provides UTXO testing utilities.

Jump to

Keyboard shortcuts

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