asset

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: BlueOak-1.0.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const Simnet = Regtest

Simnet is an alias of Regtest.

Variables

View Source
var (
	ErrInvalidPassphrase = errors.New("invalid_passphrase")
)

Functions

func DecryptData

func DecryptData(data, passphrase []byte) ([]byte, error)

DecryptData uses the provided passphrase to decrypt the provided data.

func EncryptData

func EncryptData(data, passphrase []byte) ([]byte, error)

EncryptData encrypts the provided data with the provided passphrase.

func ReEncryptData

func ReEncryptData(data, oldPass, newPass []byte) ([]byte, error)

ReEncryptData decrypts the provided data using the oldPass and re-encrypts the data using newPass.

Types

type CreateWalletParams

type CreateWalletParams struct {
	OpenWalletParams
	Pass     []byte
	Birthday time.Time
}

CreateWalletParams are the parameters for creating a wallet.

type Network

type Network uint8

Network flags passed to asset backends to signify which network to use.

const (
	Mainnet Network = iota
	Testnet
	Regtest
)

func NetFromString

func NetFromString(net string) (Network, error)

NetFromString returns the Network for the given network name.

func (Network) String

func (n Network) String() string

String returns the string representation of a Network.

type OpenWalletParams

type OpenWalletParams struct {
	Net      Network
	DataDir  string
	DbDriver string
	Logger   slog.Logger
}

CreateWalletParams are the parameters for opening a wallet.

type PeerManagerChainService

type PeerManagerChainService interface {
	ConnectNode(addr string, permanent bool) error
	RemoveNodeByAddr(addr string) error
	Peers() []SPVPeer
}

PeerManagerChainService are the functions needed for an SPVPeerManager to communicate with a chain service.

type PeerSource

type PeerSource uint16
const (
	AddedPeer PeerSource = iota
	DefaultPeer
	DiscoveredPeer
)

type RecoveryCfg

type RecoveryCfg struct {
	Seed                 []byte
	Birthday             time.Time
	NumExternalAddresses uint32
	NumInternalAddresses uint32
}

RecoveryCfg is the information used to recover a wallet.

type SPVPeer

type SPVPeer interface {
	StartingHeight() int32
	LastBlock() int32
	Addr() string
}

SPVPeer is satisfied by *neutrino.ServerPeer, but is generalized to accommodate underlying implementations other than lightninglabs/neutrino.

type SPVPeerManager

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

SPVPeerManager implements peer management functionality for all bitcoin clone SPV wallets.

func NewSPVPeerManager

func NewSPVPeerManager(cs PeerManagerChainService, defaultPeers []string, savedPeersFilePath string, log slog.Logger, defaultPort string) *SPVPeerManager

NewSPVPeerManager creates a new SPVPeerManager.

func (*SPVPeerManager) AddPeer

func (s *SPVPeerManager) AddPeer(addr string) error

AddPeer connects to a new peer and stores it in the db.

func (*SPVPeerManager) ConnectToInitialWalletPeers

func (s *SPVPeerManager) ConnectToInitialWalletPeers()

ConnectToInitialWalletPeers connects to the default peers and the peers that were added by the user and persisted in the db.

func (*SPVPeerManager) Peers

func (s *SPVPeerManager) Peers() ([]*WalletPeer, error)

Peers returns the list of peers that the wallet is connected to. It also returns the peers that the user added that the wallet may not currently be connected to.

func (*SPVPeerManager) RemovePeer

func (s *SPVPeerManager) RemovePeer(addr string) error

RemovePeer disconnects from a peer added by the user and removes it from the db.

type WalletBase

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

func NewWalletBase

func NewWalletBase(params OpenWalletParams, seed, walletPass []byte, birthday time.Time, traits WalletTrait) (*WalletBase, error)

NewWalletBase initializes a WalletBase using the information provided. The wallet's seed is encrypted and saved, along with other basic wallet info.

func OpenWalletBase

func OpenWalletBase(params OpenWalletParams) (*WalletBase, error)

OpenWalletBase loads basic information for an existing wallet from the provided params.

func (*WalletBase) AccountDiscoveryRequired

func (w *WalletBase) AccountDiscoveryRequired() bool

func (*WalletBase) DataDir

func (w *WalletBase) DataDir() string

func (*WalletBase) DecryptSeed

func (w *WalletBase) DecryptSeed(passphrase []byte) (string, error)

DecryptSeed decrypts the encrypted wallet seed using the provided passphrase and returns the mnemonic.

func (WalletBase) InitializeSyncContext

func (sh WalletBase) InitializeSyncContext(ctx context.Context) (context.Context, error)

InitializeSyncContext returns a context that should be used for bacgkround sync processes. All sync background processes should exit when the returned context is canceled. Call SyncEnded() when all sync processes have ended.

func (*WalletBase) IsRestored

func (w *WalletBase) IsRestored() bool

func (WalletBase) IsSyncingOrSynced

func (sh WalletBase) IsSyncingOrSynced() bool

IsSyncingOrSynced is true if the wallet synchronization was started.

func (*WalletBase) IsWatchOnly

func (w *WalletBase) IsWatchOnly() bool

func (*WalletBase) MarkAccountDiscoveryComplete

func (w *WalletBase) MarkAccountDiscoveryComplete()

func (*WalletBase) Network

func (w *WalletBase) Network() Network

func (*WalletBase) ReEncryptSeed

func (w *WalletBase) ReEncryptSeed(oldPass, newPass []byte) error

func (*WalletBase) SeedVerificationRequired

func (w *WalletBase) SeedVerificationRequired() bool

SeedVerificationRequired is true if the seed for this wallet is yet to be verified by the owner. The wallet's seed is saved in an encrypted form until it is verified.

func (WalletBase) StopSync

func (sh WalletBase) StopSync()

StopSync cancels the wallet's synchronization to the blockchain network. It may take a few moments for sync to completely stop. Use

func (WalletBase) SyncEnded

func (sh WalletBase) SyncEnded(err error)

SyncEnded signals that all sync processes have been stopped.

func (WalletBase) SyncIsStopping

func (sh WalletBase) SyncIsStopping() bool

func (*WalletBase) VerifySeed

func (w *WalletBase) VerifySeed(seedMnemonic string, passphrase []byte) (bool, error)

VerifySeed decrypts the encrypted wallet seed using the provided passphrase and compares it with the provided seedMnemonic. If it's a match, the wallet seed will no longer be saved.

func (WalletBase) WaitForSyncToStop

func (sh WalletBase) WaitForSyncToStop()

WaitForSyncToStop blocks until the wallet synchronization is fully stopped.

type WalletPeer

type WalletPeer struct {
	Addr      string     `json:"addr"`
	Source    PeerSource `json:"source"`
	Connected bool       `json:"connected"`
}

WalletPeer provides information about a wallet's peer.

type WalletTrait

type WalletTrait uint64

WalletTrait is a bitset indicating various optional wallet properties, such as if the wallet was restored or if it's watch only.

const (
	WalletTraitRestored  WalletTrait = 1 << iota // The Wallet is a restored wallet.
	WalletTraitWatchOnly                         // The Wallet is a watch only wallet.
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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