wallet

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: BSD-3-Clause Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTransaction = errors.New("invalid transaction type")
	ErrInsufficientFunds  = errors.New("insufficient funds")
	ErrInvalidAddress     = errors.New("invalid address")
	ErrUnsupportedChain   = errors.New("unsupported chain type")
	ErrNilKeyManager      = errors.New("nil key manager")
)

Functions

func MatchOwners

func MatchOwners(
	owners *secp256k1fx.OutputOwners,
	addrs set.Set[ids.ShortID],
	minIssuanceTime uint64,
) ([]uint32, bool)

MatchOwners attempts to match a list of addresses up to the provided threshold.

Types

type BridgeAttestation

type BridgeAttestation struct {
	SourceChain      ChainType
	DestinationChain ChainType
	MessageID        ids.ID
	Payload          []byte
	Validators       []ids.NodeID
	Signatures       [][]byte // Classical signatures
	RingtailSig      []byte   // Aggregated Ringtail signature
}

BridgeAttestation represents a cross-chain message attestation

type BridgeRequest

type BridgeRequest struct {
	SourceChain      ChainType
	DestinationChain ChainType
	AssetID          ids.ID
	Amount           *big.Int
	Recipient        string
	Data             []byte
}

BridgeRequest represents a cross-chain transaction request

type BridgeWallet

type BridgeWallet interface {
	Wallet

	// CreateBridgeTransaction creates a cross-chain transaction
	CreateBridgeTransaction(ctx context.Context, req *BridgeRequest) (UnsignedTransaction, error)

	// VerifyBridgeAttestation verifies a bridge attestation with Ringtail signatures
	VerifyBridgeAttestation(ctx context.Context, attestation *BridgeAttestation) error
}

BridgeWallet extends Wallet with cross-chain capabilities

type ChainType

type ChainType string

ChainType represents different blockchain architectures

const (
	ChainTypeLuxPrimary  ChainType = "lux-primary"  // P-Chain, X-Chain, C-Chain
	ChainTypeLuxL2       ChainType = "lux-l2"       // SubnetEVM
	ChainTypeOPStack     ChainType = "op-stack"     // OP Stack on Lux
	ChainTypeBasedRollup ChainType = "based-rollup" // Based Rollup settling on Lux
	ChainTypeBitcoin     ChainType = "bitcoin"      // Bitcoin network
	ChainTypeXRPL        ChainType = "xrpl"         // XRP Ledger
	ChainTypeEVM         ChainType = "evm"          // Generic EVM chain
)

type ChainUTXOs

type ChainUTXOs interface {
	AddUTXO(ctx context.Context, destinationChainID ids.ID, utxo *lux.UTXO) error
	RemoveUTXO(ctx context.Context, sourceChainID, utxoID ids.ID) error

	UTXOs(ctx context.Context, sourceChainID ids.ID) ([]*lux.UTXO, error)
	GetUTXO(ctx context.Context, sourceChainID, utxoID ids.ID) (*lux.UTXO, error)
}

func NewChainUTXOs

func NewChainUTXOs(chainID ids.ID, utxos UTXOs) ChainUTXOs

type ConfirmationReceipt

type ConfirmationReceipt struct {
	// Identifies the primary chain ("P", "X" or "C")
	ChainAlias string
	// ID of the issued transaction
	TxID ids.ID
	// The time from initiation to confirmation
	TotalDuration time.Duration
	// The time from issuance to confirmation. It does not include the duration
	// of issuance.
	ConfirmationDuration time.Duration
}

ConfirmationReceipt is the information known after issuing and confirming a transaction.

type Factory

type Factory interface {
	// CreateWallet creates a wallet for the specified chain
	CreateWallet(ctx context.Context, chainType ChainType, keyManager KeyManager, config interface{}) (Wallet, error)

	// CreateBridgeWallet creates a bridge-enabled wallet
	CreateBridgeWallet(ctx context.Context, chainType ChainType, keyManager KeyManager, config interface{}) (BridgeWallet, error)
}

Factory creates wallets for different chain types

type IssuanceReceipt

type IssuanceReceipt struct {
	// Identifies the primary chain ("P", "X" or "C")
	ChainAlias string
	// ID of the issued transaction
	TxID ids.ID
	// The time from initiation to issuance
	Duration time.Duration
}

IssuanceReceipt is the information known after issuing a transaction.

type KeyManager

type KeyManager interface {
	// GetPrivateKey returns the ECDSA private key
	GetPrivateKey() *ecdsa.PrivateKey

	// GetPublicKey returns the ECDSA public key
	GetPublicKey() *ecdsa.PublicKey

	// GetRingtailShare returns the Ringtail key share if available
	GetRingtailShare() []byte

	// Sign signs a message
	Sign(message []byte) ([]byte, error)

	// SignWithRingtail signs with Ringtail if available
	SignWithRingtail(message []byte) ([]byte, error)
}

KeyManager manages keys for different wallet types

type Option

type Option func(*Options)

func UnionOptions

func UnionOptions(first, second []Option) []Option

func WithAssumeDecided

func WithAssumeDecided() Option

func WithBaseFee

func WithBaseFee(baseFee *big.Int) Option

func WithChangeOwner

func WithChangeOwner(changeOwner *secp256k1fx.OutputOwners) Option

func WithConfirmationHandler

func WithConfirmationHandler(f func(ConfirmationReceipt)) Option

func WithContext

func WithContext(ctx context.Context) Option

func WithCustomAddresses

func WithCustomAddresses(addrs set.Set[ids.ShortID]) Option

func WithCustomEthAddresses

func WithCustomEthAddresses(addrs set.Set[common.Address]) Option

func WithIssuanceHandler

func WithIssuanceHandler(f func(IssuanceReceipt)) Option

func WithMemo

func WithMemo(memo []byte) Option

func WithMinIssuanceTime

func WithMinIssuanceTime(minIssuanceTime uint64) Option

func WithPollFrequency

func WithPollFrequency(pollFrequency time.Duration) Option

func WithStakeableLocked

func WithStakeableLocked() Option

type Options

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

func NewOptions

func NewOptions(ops []Option) *Options

func (*Options) Addresses

func (o *Options) Addresses(defaultAddresses set.Set[ids.ShortID]) set.Set[ids.ShortID]

func (*Options) AllowStakeableLocked

func (o *Options) AllowStakeableLocked() bool

func (*Options) AssumeDecided

func (o *Options) AssumeDecided() bool

func (*Options) BaseFee

func (o *Options) BaseFee(defaultBaseFee *big.Int) *big.Int

func (*Options) ChangeOwner

func (o *Options) ChangeOwner(defaultOwner *secp256k1fx.OutputOwners) *secp256k1fx.OutputOwners

func (*Options) ConfirmationHandler

func (o *Options) ConfirmationHandler() func(ConfirmationReceipt)

func (*Options) Context

func (o *Options) Context() context.Context

func (*Options) EthAddresses

func (o *Options) EthAddresses(defaultAddresses set.Set[common.Address]) set.Set[common.Address]

func (*Options) IssuanceHandler

func (o *Options) IssuanceHandler() func(IssuanceReceipt)

func (*Options) Memo

func (o *Options) Memo() []byte

func (*Options) MinIssuanceTime

func (o *Options) MinIssuanceTime() uint64

func (*Options) PollFrequency

func (o *Options) PollFrequency() time.Duration

type SignedTransaction

type SignedTransaction interface {
	UnsignedTransaction

	// GetSignatures returns the signatures
	GetSignatures() [][]byte

	// GetRingtailSignature returns the Ringtail signature if present
	GetRingtailSignature() []byte
}

SignedTransaction represents a signed transaction

type TransactionRequest

type TransactionRequest struct {
	To      string
	AssetID ids.ID
	Amount  *big.Int
	Fee     *big.Int
	Data    []byte      // For contract calls
	Memo    []byte      // For UTXO chains
	Extra   interface{} // Chain-specific data
}

TransactionRequest represents a generic transaction request

type TransactionStatus

type TransactionStatus struct {
	ID          ids.ID
	Status      string // pending, confirmed, failed
	BlockNumber uint64
	BlockHash   ids.ID
	Timestamp   uint64
}

TransactionStatus represents the status of a transaction

type UTXOs

type UTXOs interface {
	AddUTXO(ctx context.Context, sourceChainID, destinationChainID ids.ID, utxo *lux.UTXO) error
	RemoveUTXO(ctx context.Context, sourceChainID, destinationChainID, utxoID ids.ID) error

	UTXOs(ctx context.Context, sourceChainID, destinationChainID ids.ID) ([]*lux.UTXO, error)
	GetUTXO(ctx context.Context, sourceChainID, destinationChainID, utxoID ids.ID) (*lux.UTXO, error)
}

func NewUTXOs

func NewUTXOs() UTXOs

type UnsignedTransaction

type UnsignedTransaction interface {
	// GetID returns the transaction ID
	GetID() ids.ID

	// GetChainType returns the chain type
	GetChainType() ChainType

	// Bytes returns the serialized transaction
	Bytes() []byte
}

UnsignedTransaction represents an unsigned transaction

type Wallet

type Wallet interface {
	// GetChainType returns the type of blockchain this wallet manages
	GetChainType() ChainType

	// GetWalletType returns whether this is UTXO or account-based
	GetWalletType() WalletType

	// GetAddress returns the primary address for this wallet
	GetAddress() string

	// GetBalance returns the balance for a specific asset
	GetBalance(ctx context.Context, assetID ids.ID) (*big.Int, error)

	// CreateTransaction creates a new transaction
	CreateTransaction(ctx context.Context, req *TransactionRequest) (UnsignedTransaction, error)

	// SignTransaction signs a transaction
	SignTransaction(ctx context.Context, tx UnsignedTransaction) (SignedTransaction, error)

	// BroadcastTransaction broadcasts a signed transaction
	BroadcastTransaction(ctx context.Context, tx SignedTransaction) (ids.ID, error)

	// GetTransactionStatus returns the status of a transaction
	GetTransactionStatus(ctx context.Context, txID ids.ID) (TransactionStatus, error)
}

Wallet provides a unified interface for different blockchain wallets

type WalletType

type WalletType string

WalletType represents the wallet model

const (
	WalletTypeUTXO    WalletType = "utxo"
	WalletTypeAccount WalletType = "account"
)

Jump to

Keyboard shortcuts

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