Documentation
¶
Index ¶
- Variables
- func GetAccountNamespace(rootPath string, index uint32) string
- type Account
- type AccountInfo
- type AddressInfo
- type Balance
- type ExternalScriptEvent
- type ExternalScriptEventType
- type ExternalScriptRepository
- type IMnemonicCypher
- type IMnemonicStore
- type Transaction
- type TransactionEvent
- type TransactionEventType
- type TransactionRepository
- type Utxo
- func (u *Utxo) CanUnlock() bool
- func (u *Utxo) Confirm(status UtxoStatus) error
- func (u *Utxo) Info() UtxoInfo
- func (u *Utxo) IsConfidential() bool
- func (u *Utxo) IsConfirmed() bool
- func (u *Utxo) IsLocked() bool
- func (u *Utxo) IsRevealed() bool
- func (u *Utxo) IsSpent() bool
- func (u *Utxo) Key() UtxoKey
- func (u *Utxo) Lock(timestamp, expiryTimestamp int64)
- func (u *Utxo) Spend(status UtxoStatus) error
- func (u *Utxo) Unlock()
- type UtxoEvent
- type UtxoEventType
- type UtxoInfo
- type UtxoKey
- type UtxoRepository
- type UtxoStatus
- type Wallet
- func (w *Wallet) AllDerivedAddressesForAccount(accountName string) ([]AddressInfo, error)
- func (w *Wallet) AllDerivedExternalAddressesForAccount(accountName string) ([]AddressInfo, error)
- func (w *Wallet) ChangePassword(currentPassword, newPassword string) error
- func (w *Wallet) CreateAccount(label string, birthdayBlock uint32, unconf bool) (*Account, error)
- func (w *Wallet) DeleteAccount(accountName string) error
- func (w *Wallet) DeriveNextExternalAddressForAccount(accountName string) (*AddressInfo, error)
- func (w *Wallet) DeriveNextInternalAddressForAccount(accountName string) (*AddressInfo, error)
- func (w *Wallet) GetAccount(accountName string) (*Account, error)
- func (w *Wallet) GetMnemonic() ([]string, error)
- func (w *Wallet) IsInitialized() bool
- func (w *Wallet) IsLocked() bool
- func (w *Wallet) IsValidPassword(password string) bool
- func (w *Wallet) Lock(password string) error
- func (w *Wallet) SetLabelForAccount(accountName, label string) error
- func (w *Wallet) Unlock(password string) error
- type WalletEvent
- type WalletEventType
- type WalletRepository
Constants ¶
This section is empty.
Variables ¶
var ( ErrWalletMissingMnemonic = fmt.Errorf("missing mnemonic") ErrWalletMissingPassword = fmt.Errorf("missing password") ErrWalletMissingNetwork = fmt.Errorf("missing network name") ErrWalletMissingBirthdayBlock = fmt.Errorf("missing birthday block height") ErrWalletLocked = fmt.Errorf("wallet is locked") ErrWalletUnlocked = fmt.Errorf("wallet must be locked") ErrWalletMaxAccountNumberReached = fmt.Errorf("reached max number of accounts") ErrWalletInvalidPassword = fmt.Errorf("wrong password") ErrWalletInvalidNetwork = fmt.Errorf("unknown network") ErrAccountNotFound = fmt.Errorf("account not found in wallet") )
var (
ErrUtxoAlreadyLocked = fmt.Errorf("utxo is already locked")
)
Functions ¶
func GetAccountNamespace ¶ added in v0.1.16
GetAccountNamespace generates a unique account namespace from the given root path and account derivation index.
Types ¶
type Account ¶
type Account struct {
AccountInfo
Index uint32
BirthdayBlock uint32
NextExternalIndex uint
NextInternalIndex uint
DerivationPathByScript map[string]string
Unconf bool
}
Account defines the entity data struture for a derived account of the daemon's HD wallet
type AccountInfo ¶
AccountInfo holds basic info about an account.
func (*AccountInfo) GetMasterBlindingKey ¶ added in v0.1.16
func (i *AccountInfo) GetMasterBlindingKey() (string, error)
type AddressInfo ¶
type AddressInfo struct {
Account string
Address string
BlindingKey []byte
DerivationPath string
Script string
}
AddressInfo holds useful info about a derived address.
type ExternalScriptEvent ¶ added in v0.2.0
type ExternalScriptEvent struct {
EventType ExternalScriptEventType
Info AddressInfo
}
ExternalScriptEvent holds info about an event occured within the repository.
type ExternalScriptEventType ¶ added in v0.2.0
type ExternalScriptEventType int
const ( ExternalScriptAdded ExternalScriptEventType = iota ExternalScriptDeleted )
func (ExternalScriptEventType) String ¶ added in v0.2.0
func (t ExternalScriptEventType) String() string
type ExternalScriptRepository ¶ added in v0.2.0
type ExternalScriptRepository interface {
// AddScripts persists the given external script by preventing duplicates.
AddScript(ctx context.Context, script AddressInfo) (bool, error)
// GetAllScripts returns all the persisted external scripts.
GetAllScripts(ctx context.Context) ([]AddressInfo, error)
// DeleteScript removes an external script idenitified by its hash from the store.
DeleteScript(ctx context.Context, scriptHash string) (bool, error)
}
ExternalScriptRepository is the abstraction for any kind of database intended to persist external scripts as AddressInfo.
type IMnemonicCypher ¶
type IMnemonicCypher interface {
Encrypt(mnemonic, password []byte) ([]byte, error)
Decrypt(encryptedMnemonic, password []byte) ([]byte, error)
}
IMnemonicCipher defines the methods a cypher must implement to encrypt or decrypt a mnemonic with a password.
var MnemonicCypher IMnemonicCypher
type IMnemonicStore ¶
IMnemonicStore defines the methods a store storing a mnemonic in plaintext must implement to either set, unset or get it.
var MnemonicStore IMnemonicStore
type Transaction ¶
type Transaction struct {
TxID string
TxHex string
BlockHash string
BlockHeight uint64
Accounts map[string]struct{}
}
Transaction is the data structure representing an Elements tx with extra info like whether it is conifirmed/unconfirmed and the name of the accounts owning one or more of its inputs.
func (*Transaction) AddAccount ¶
func (t *Transaction) AddAccount(accountName string)
AddAccount adds the given account to the map of those involved in the tx.
func (*Transaction) Confirm ¶
func (t *Transaction) Confirm(blockHash string, blockHeight uint64)
Confirm marks the tx as confirmed.
func (*Transaction) GetAccounts ¶
func (t *Transaction) GetAccounts() []string
GetAccounts returns the account map as a slice of account names.
func (*Transaction) HasAccounts ¶
func (t *Transaction) HasAccounts(tx *Transaction) bool
HasAccounts returns whether the current tx contains all account names of the provided one.
func (*Transaction) IsConfirmed ¶
func (t *Transaction) IsConfirmed() bool
IsConfirmed returns whther the tx is included in the blockchain.
type TransactionEvent ¶
type TransactionEvent struct {
EventType TransactionEventType
Transaction *Transaction
}
TransactionEvent holds info about an event occured within the repository.
type TransactionEventType ¶
type TransactionEventType int
const ( TransactionAdded TransactionEventType = iota TransactionUnconfirmed TransactionConfirmed )
func (TransactionEventType) String ¶
func (t TransactionEventType) String() string
type TransactionRepository ¶
type TransactionRepository interface {
// AddTransaction adds the provided transaction to the repository by
// preventing duplicates.
// Generates a TransactionAdded event if successful.
AddTransaction(ctx context.Context, tx *Transaction) (bool, error)
// ConfirmTransaction adds the given blockhash and block height to the
// Transaction identified by the given txid.
// Generates a TransactionConfirmed event if successful.
ConfirmTransaction(
ctx context.Context, txid, blockHash string, blockheight uint64,
) (bool, error)
// GetTransaction returns the Transaction identified by the given txid.
GetTransaction(ctx context.Context, txid string) (*Transaction, error)
// UpdateTransaction allows to commit multiple changes to the same
// Transaction in a transactional way.
UpdateTransaction(
ctx context.Context, txid string,
updateFn func(tx *Transaction) (*Transaction, error),
) error
// GetEventChannel retunrs the channel of TransactionEvents.
GetEventChannel() chan TransactionEvent
}
TransactionRepository is the abstraction for any kind of database intended to persist Transactions.
type Utxo ¶
type Utxo struct {
UtxoKey
Value uint64
Asset string
ValueCommitment []byte
AssetCommitment []byte
ValueBlinder []byte
AssetBlinder []byte
Script []byte
Nonce []byte
RangeProof []byte
SurjectionProof []byte
AccountName string
LockTimestamp int64
LockExpiryTimestamp int64
SpentStatus UtxoStatus
ConfirmedStatus UtxoStatus
}
Utxo is the data structure representing an Elements UTXO with extra info like whether it is spent/utxo, confirmed/unconfirmed or locked/unlocked and the name of the account owning it.
func (*Utxo) Confirm ¶
func (u *Utxo) Confirm(status UtxoStatus) error
Confirm marks the utxos as confirmed.
func (*Utxo) IsConfidential ¶
IsConfidential returns whether the utxo is a confidential one.
func (*Utxo) IsConfirmed ¶
IsConfirmed returns whether the utxo is confirmed.
func (*Utxo) IsRevealed ¶
IsRevealed returns whether the utxo is confidential and its blinded data (value, asset and relative blinders) have been revealed.
type UtxoEvent ¶
type UtxoEvent struct {
EventType UtxoEventType
Utxos []UtxoInfo
}
UtxoEvent holds info about an event occured within the repository.
type UtxoEventType ¶
type UtxoEventType int
const ( UtxoAdded UtxoEventType = iota UtxoConfirmed UtxoLocked UtxoUnlocked UtxoSpent )
func (UtxoEventType) String ¶
func (t UtxoEventType) String() string
type UtxoInfo ¶
type UtxoInfo struct {
UtxoKey
Value uint64
Asset string
Script []byte
ValueBlinder []byte
AssetBlinder []byte
AccountName string
SpentStatus UtxoStatus
ConfirmedStatus UtxoStatus
}
UtxoInfo holds sensitive info about the utxo. For confidential utxos. they must be revealed to return useful UtxoInfo.
type UtxoRepository ¶
type UtxoRepository interface {
// AddUtxos adds the provided utxos to the repository by preventing
// duplicates.
// Generates a UtxoAdded event if successfull.
AddUtxos(ctx context.Context, utxos []*Utxo) (int, error)
// GetUtxosByKey returns the utxos identified by the given keys.
GetUtxosByKey(ctx context.Context, utxoKeys []UtxoKey) ([]*Utxo, error)
// GetAllUtxos returns the entire UTXO set, included those locked or
// already spent.
GetAllUtxos(ctx context.Context) ([]*Utxo, error)
// GetSpendableUtxos returns all unlocked utxo UTXOs.
GetSpendableUtxos(ctx context.Context) ([]*Utxo, error)
// GetAllUtxosForAccount returns the list of all utxos for the given
// account.
GetAllUtxosForAccount(ctx context.Context, account string) ([]*Utxo, error)
// GetSpendableUtxosForAccount returns the list of spendable utxos for the
// given account. The list incldues only confirmed and unlocked utxos.
GetSpendableUtxosForAccount(ctx context.Context, account string) ([]*Utxo, error)
// GetLockedUtxosForAccount returns the list of all currently locked utxos
// for the given account.
GetLockedUtxosForAccount(ctx context.Context, account string) ([]*Utxo, error)
// GetBalanceForAccount returns the confirmed, unconfirmed and locked
// balances per each asset for the given account.
GetBalanceForAccount(ctx context.Context, account string) (map[string]*Balance, error)
// SpendUtxos updates the status of the given list of utxos to "spent".
// Generates a UtxoSpent event if successfull.
SpendUtxos(ctx context.Context, utxoKeys []UtxoKey, status UtxoStatus) (int, error)
// ConfirmUtxos updates the status of the given list of utxos to "confirmed".
// Generates a UtxoConfirmed event if successfull.
ConfirmUtxos(ctx context.Context, utxoKeys []UtxoKey, status UtxoStatus) (int, error)
// LockUtxos updates the status of the given list of utxos to "locked".
// Generates a UtxoLocked event if successfull.
LockUtxos(ctx context.Context, utxoKeys []UtxoKey, timestamp, expiryTimestamp int64) (int, error)
// UnlockUtxos updates the status of the given list of utxos to "unlocked".
// Generates a UtxoUnlocked event if successfull.
UnlockUtxos(ctx context.Context, utxoKeys []UtxoKey) (int, error)
// DeleteUtxosForAccount deletes every utxo associated to the given account
// from the repository.
DeleteUtxosForAccount(ctx context.Context, accountName string) error
// GetEventChannel returns the channel of UtxoEvents.
GetEventChannel() chan UtxoEvent
}
UtxoRepository is the abstraction for any kind of database intended to persist Utxos.
type UtxoStatus ¶
type Wallet ¶
type Wallet struct {
EncryptedMnemonic []byte
PasswordHash []byte
BirthdayBlockHeight uint32
RootPath string
NetworkName string
Accounts map[string]*Account
AccountsByLabel map[string]string
NextAccountIndex uint32
}
Wallet is the data structure representing a secure HD wallet, ie. protected by a password that encrypts/decrypts the mnemonic seed.
func NewWallet ¶
func NewWallet( mnemonic []string, password, rootPath, network string, birthdayBlock uint32, accounts []Account, ) (*Wallet, error)
NewWallet encrypts the provided mnemonic with the passhrase and returns a new Wallet initialized with the encrypted mnemonic, the hash of the password, the given root path, network and possible a list of accounts for an already used one. The Wallet is locked by default since it is initialized without the mnemonic in plain text.
func (*Wallet) AllDerivedAddressesForAccount ¶
func (w *Wallet) AllDerivedAddressesForAccount( accountName string, ) ([]AddressInfo, error)
AllDerivedAddressesForAccount returns info about all derived receiving and change addresses derived so far for the given account.
func (*Wallet) AllDerivedExternalAddressesForAccount ¶
func (w *Wallet) AllDerivedExternalAddressesForAccount( accountName string, ) ([]AddressInfo, error)
AllDerivedExternalAddressesForAccount returns info about all derived receiving addresses derived so far for the given account.
func (*Wallet) ChangePassword ¶
ChangePassword attempts to unlock the wallet with the given currentPassword, then encrypts the plaintext mnemonic again with new password, stores its hash and, finally, locks the Wallet again.
func (*Wallet) CreateAccount ¶
CreateAccount creates a new account with the given name by preventing collisions with existing ones. If successful, returns the Account created.
func (*Wallet) DeleteAccount ¶
DeleteAccount safely removes an Account and all related stored info from the Wallet.
func (*Wallet) DeriveNextExternalAddressForAccount ¶
func (w *Wallet) DeriveNextExternalAddressForAccount( accountName string, ) (*AddressInfo, error)
DeriveNextExternalAddressForAccount returns all useful info about the next new receiving address for the given account.
func (*Wallet) DeriveNextInternalAddressForAccount ¶
func (w *Wallet) DeriveNextInternalAddressForAccount( accountName string, ) (*AddressInfo, error)
DeriveNextInternalAddressForAccount returns all useful info about the next new change address for the given account.
func (*Wallet) GetAccount ¶
GetAccount safely returns an Account identified by the given name.
func (*Wallet) GetMnemonic ¶
GetMnemonic safely returns the plaintext mnemonic.
func (*Wallet) IsInitialized ¶
IsInitialized returns wheter the wallet is initialized with an encrypted mnemonic.
func (*Wallet) IsLocked ¶
IsLocked returns whether the wallet is initialized and the plaintext mnemonic is set in its store.
func (*Wallet) IsValidPassword ¶ added in v0.1.14
func (*Wallet) SetLabelForAccount ¶ added in v0.1.16
SetLabelForAccount changes the label for the given account
type WalletEvent ¶
type WalletEvent struct {
EventType WalletEventType
AccountName string
AccountBirthdayBlock uint32
AccountAddresses []AddressInfo
}
WalletEvent holds info about an event occured within the repository.
type WalletEventType ¶
type WalletEventType int
const ( WalletCreated WalletEventType = iota WalletUnlocked WalletLocked WalletPasswordChanged WalletAccountCreated WalletAccountAddressesDerived WalletAccountDeleted )
func (WalletEventType) String ¶
func (t WalletEventType) String() string
type WalletRepository ¶
type WalletRepository interface {
// CreateWallet stores a new Wallet if not yet existing.
// Generates a WalletCreated event if successfull.
CreateWallet(ctx context.Context, wallet *Wallet) error
// GetWallet returns the stored wallet, if existing.
GetWallet(ctx context.Context) (*Wallet, error)
// UnlockWallet attempts to update the status of the Wallet to "unlocked".
// Generates a WalletUnlocked event if successfull.
UnlockWallet(ctx context.Context, password string) error
// LockkWallet updates the status of the Wallet to "locked".
// Generates a WalletLocked event if successfull.
LockWallet(ctx context.Context, password string) error
// UpdateWallet allows to make multiple changes to the Wallet in a
// transactional way.
UpdateWallet(
ctx context.Context, updateFn func(v *Wallet) (*Wallet, error),
) error
// CreateAccount creates a new wallet account with the given name and returns
// its basic info.
// Generates a WalletAccountCreated event if successfull.
CreateAccount(
ctx context.Context, accountName string, birthdayBlock uint32, unconf bool,
) (*AccountInfo, error)
// DeriveNextExternalAddressesForAccount returns one or more new receiving
// addresses for the given account.
// Generates a WalletAccountAddressesDerived event if successfull.
DeriveNextExternalAddressesForAccount(
ctx context.Context, accountName string, numOfAddresses uint64,
) ([]AddressInfo, error)
// DeriveNextInternalAddressesForAccount returns one or more new change
// addresses for the given account.
// Generates a WalletAccountAddressesDerived event if successfull.
DeriveNextInternalAddressesForAccount(
ctx context.Context, accountName string, numOfAddresses uint64,
) ([]AddressInfo, error)
// DeleteAccount deletes the wallet account with the given name.
// Generates a WalletAccountDeleted event if successfull.
DeleteAccount(ctx context.Context, accountName string) error
// GetEventChannel returns the channel of WalletEvents.
GetEventChannel() chan WalletEvent
}
WalletRepository is the abstraction for any kind of database intended to persist a Wallet.