src

package
v0.0.0-...-f73c8e4 Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDirectoryPath = "~/.blindbitd"
View Source
const PathEndingConfig = "/blindbit.toml"
View Source
const PathEndingKeys = dataPath + "/keys"
View Source
const PathEndingSocketDirPath = "/run"
View Source
const PathEndingSocketPath = PathEndingSocketDirPath + "/blindbit.socket"
View Source
const PathEndingWallet = dataPath + "/wallet"
View Source
const StandardAddressComment = "standard"

StandardAddressComment Identifier for the base non-labelled address

Variables

View Source
var (
	ErrLabelAlreadyExists = errors.New("label already exists")

	ErrMinChangeAmountNotReached = errors.New("min change amount not reached")

	ErrWrongLengthRecipients = errors.New("wrong length new recipients")

	ErrRecipientIncomplete = errors.New("recipient incomplete")

	ErrNotSPAddress = errors.New("not a sp address")

	ErrNoUTXOsInWallet = errors.New("no utxos in wallet")

	ErrInsufficientFunds = errors.New("insufficient funds")

	ErrNoMatchForUTXO = errors.New("could not match UTXO to foundOutput, should not happen")

	ErrTxInputAndVinLengthMismatch = errors.New("tx inputs and vins have different length, should not happen")

	ErrNoMatchingVinFoundForTxInput = errors.New("there was no matching vin for the given tx input, should not happen")

	ErrDaemonNotSet = errors.New("daemon is not initialised")

	ErrDaemonIsLocked = errors.New("daemon is locked")

	ErrInvalidFeeRate = errors.New("invalid fee rate")

	ErrRecipientAmountIsZero = errors.New("recipient amount is zero")
)

todo group by logical context errors with `should not happen` indicate a bug in the program and not necessarily user input errors

View Source
var (
	DirectoryPath = "~/.blindbitd"

	PathLogs string

	PathIpcSocketDir string
	PathIpcSocket    string

	PathConfig string

	PathDbWallet string

	PathToKeys string
)
View Source
var (

	// BlindBitServerAddress Indexing server for silent payments that follows the blindbit standard
	BlindBitServerAddress string
	// ElectrumServerAddress Electrum server
	ElectrumServerAddress string

	// MinChangeAmount The wallet will never create change that is smaller than this value. Value has to be in sats.
	MinChangeAmount int64
	// DustLimit only receives amounts and checks tweaks where the biggest utxo exceeds the dust limit.
	// Note: that if you receive funds below this threshold you might not find them.
	// Rescan with DustLimit = 0 to find those.
	DustLimit uint64

	// ChainParams defines on which chain the wallet runs
	ChainParams *chaincfg.Params

	// ElectrumTorProxyHost if the host addr is given, tor will be used normally "127.0.0.1:9050". This is also the default setting
	ElectrumTorProxyHost = ""

	// UseElectrum no electrum calls will be made if false. Setting an electrum address wil set to true in settings.
	UseElectrum bool

	// AutomaticScanInterval has different values depending on whether Electrum is used or not
	AutomaticScanInterval time.Duration = 5 * time.Minute // 5 minutes if electrum is active
)
View Source
var Empty32Arr = bip352.ConvertToFixedLength32(bytes.Repeat([]byte{0x00}, 32))
View Source
var Empty33Arr = bip352.ConvertToFixedLength33(bytes.Repeat([]byte{0x00}, 33))

Functions

func ConvertOwnedUTXOIntoVin

func ConvertOwnedUTXOIntoVin(utxo *OwnedUTXO) bip352.Vin

func LoadConfigs

func LoadConfigs(pathToConfig string)

func SetPaths

func SetPaths(baseDirectory string)

Types

type Address

type Address struct {
	Address string
	Comment string
}

type Addresses

type Addresses map[string]string

Addresses maps the address to an annotation the annotation might be empty

type Keys

type Keys struct {
	ScanSecretKey  [32]byte
	SpendSecretKey [32]byte
	Mnemonic       string
}

func CreateNewKeys

func CreateNewKeys(seedPassphrase string) (*Keys, error)

func DeriveKeysFromMaster

func DeriveKeysFromMaster(master *hdkeychain.ExtendedKey) (*Keys, error)

func KeysFromMnemonic

func KeysFromMnemonic(mnemonic, seedPassphrase string) (*Keys, error)

func (*Keys) DeSerialise

func (k *Keys) DeSerialise(data []byte) error

func (*Keys) Serialise

func (k *Keys) Serialise() ([]byte, error)

type Label

type Label struct {
	// todo add created_at field
	Comment       string `json:"comment"`
	*bip352.Label `json:"label"`
}

type LabelsMapping

type LabelsMapping map[[33]byte]Label

LabelsMapping the key is the label's pubKey, the value is the Label data

func (*LabelsMapping) GetLabelByPubKey

func (lm *LabelsMapping) GetLabelByPubKey(labelPubKey [33]byte) *Label

func (*LabelsMapping) MarshalJSON

func (lm *LabelsMapping) MarshalJSON() ([]byte, error)

func (*LabelsMapping) UnmarshalJSON

func (lm *LabelsMapping) UnmarshalJSON(data []byte) error

type OwnedUTXO

type OwnedUTXO struct {
	Txid         [32]byte      `json:"txid,omitempty"`
	Vout         uint32        `json:"vout,omitempty"`
	Amount       uint64        `json:"amount"`
	PrivKeyTweak [32]byte      `json:"priv_key_tweak,omitempty"`
	PubKey       [32]byte      `json:"pub_key,omitempty"`
	Timestamp    uint64        `json:"timestamp,omitempty"`
	State        UTXOState     `json:"utxo_state,omitempty"`
	Label        *bip352.Label `json:"label"` // the pubKey associated with the label
}

func (*OwnedUTXO) GetKey

func (u *OwnedUTXO) GetKey() ([36]byte, error)

func (*OwnedUTXO) LabelComment

func (u *OwnedUTXO) LabelComment(mapping LabelsMapping) *string

func (*OwnedUTXO) LabelPubKey

func (u *OwnedUTXO) LabelPubKey() []byte

func (*OwnedUTXO) SerialiseToOutpoint

func (u *OwnedUTXO) SerialiseToOutpoint() ([36]byte, error)

type Recipient

type Recipient struct {
	Address    string
	PkScript   []byte
	Amount     int64
	Annotation string
	Data       map[string]any
}

type UTXOMapping

type UTXOMapping map[[36]byte]struct{}

UTXOMapping the key is the utxos (txid||vout) todo marshalling or unmarshalling seems to have some issues. Investigate root cause

func (*UTXOMapping) MarshalJSON

func (um *UTXOMapping) MarshalJSON() ([]byte, error)

func (*UTXOMapping) UnmarshalJSON

func (um *UTXOMapping) UnmarshalJSON(data []byte) error

type UTXOState

type UTXOState int8
const (
	StateUnknown UTXOState = iota - 1
	StateUnconfirmed
	StateUnspent
	StateSpent
	StateUnconfirmedSpent
)

type UtxoCollection

type UtxoCollection []*OwnedUTXO

func (*UtxoCollection) DeSerialise

func (c *UtxoCollection) DeSerialise(data []byte) error

func (*UtxoCollection) Serialise

func (c *UtxoCollection) Serialise() ([]byte, error)

type Wallet

type Wallet struct {
	PubKeyScan     [33]byte        `json:"pub_key_scan"`
	PubKeySpend    [33]byte        `json:"pub_key_spend"`
	BirthHeight    uint64          `json:"birth_height,omitempty"`
	LastScanHeight uint64          `json:"last_scan,omitempty"`
	UTXOs          UtxoCollection  `json:"utxos,omitempty"`
	Labels         []*bip352.Label `json:"labels"`       // Labels contains all labels except for the change label
	ChangeLabel    *bip352.Label   `json:"change_label"` // ChangeLabel is separate in order to make it clear that it's special and is not just shown like other labels
	NextLabelM     uint32          `json:"next_label_m"` // NextLabelM indicates which m will be used to derive the next label
	// todo Important: if taken out we need to keep the tweak fro that UTXO otherwise it will be found but basically unspendable
	PubKeysToWatch [][32]byte `json:"pub_keys_to_watch"` // todo this can be taken out, we can check for new payments to old pub-keys via electrum.
	Addresses      Addresses  `json:"addresses"`
	// todo should LabelsMapping be integrated with Wallet.Labels
	LabelsMapping LabelsMapping `json:"labels_mapping"` // never show LabelsMapping addresses to the user - it includes the change label which should NEVER be shown to normal users
	UTXOMapping   UTXOMapping   `json:"utxo_mapping"`   // used to keep track of utxos and not add the same twice
	// contains filtered or unexported fields
}

func NewWallet

func NewWallet(birthHeight uint64) *Wallet

func (*Wallet) AddUTXOs

func (w *Wallet) AddUTXOs(utxos []*OwnedUTXO) error

func (*Wallet) CheckAndInitialiseFields

func (w *Wallet) CheckAndInitialiseFields() error

func (*Wallet) DeSerialise

func (w *Wallet) DeSerialise(data []byte) error

func (*Wallet) FindLabelByPubKey

func (w *Wallet) FindLabelByPubKey(pubKey [33]byte) *Label

FindLabelByPubKey returns the pointer to a Label stored in the wallet, will be nil if none was found. This is basically a wrapper function around LabelsMapping but adds the change label. Chose this approach to avoid accidentally exposing the change address.

func (*Wallet) FreeBalance

func (w *Wallet) FreeBalance() uint64

func (*Wallet) GenerateAddress

func (w *Wallet) GenerateAddress() (string, error)

func (*Wallet) GenerateChangeLabel

func (w *Wallet) GenerateChangeLabel() (string, error)

func (*Wallet) GenerateNewLabel

func (w *Wallet) GenerateNewLabel(comment string) (*Label, error)

func (*Wallet) GetFreeUTXOs

func (w *Wallet) GetFreeUTXOs(includeSpentUnconfirmed bool) UtxoCollection

func (*Wallet) GetUTXOsByStates

func (w *Wallet) GetUTXOsByStates(states ...UTXOState) UtxoCollection

func (*Wallet) LoadKeys

func (w *Wallet) LoadKeys(secretKeyScan, secretKeySpend [32]byte)

func (*Wallet) SecretKeyScan

func (w *Wallet) SecretKeyScan() [32]byte

func (*Wallet) SecretKeySpend

func (w *Wallet) SecretKeySpend() [32]byte

func (*Wallet) Serialise

func (w *Wallet) Serialise() ([]byte, error)

func (*Wallet) SortedAddresses

func (w *Wallet) SortedAddresses() ([]Address, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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