Documentation ¶
Index ¶
- Constants
- Variables
- func CheckAssetId(s string) error
- func CheckDescription(s string) error
- func CheckMemoText(s string) error
- func CheckMnemonicWord(s string) bool
- func CheckPrivateKey(s *string) bool
- func CheckPublicKey(s string) bool
- func EraseByteBuffer(b []byte)
- func EraseString(s *string)
- func SelfTest() error
- type Account
- func (a *Account) ClearMemoId(walletPassword *string) error
- func (a *Account) Description() string
- func (a *Account) HasPrivateKey() bool
- func (a *Account) IsAddressBookAccount() bool
- func (a *Account) IsOwnAccount() bool
- func (a *Account) MemoId() (bool, uint64)
- func (a *Account) MemoText() string
- func (a *Account) PrivateKey(walletPassword *string) string
- func (a *Account) PublicKey() string
- func (a *Account) SetDescription(desc string, walletPassword *string) error
- func (a *Account) SetMemoId(memo uint64, walletPassword *string) error
- func (a *Account) SetMemoText(memo string, walletPassword *string) error
- func (a *Account) Type() uint16
- type Asset
- type TradingPair
- type Wallet
- func (w *Wallet) Accounts() []*Account
- func (w *Wallet) AddAddressBookAccount(pubkey string, walletPassword *string) *Account
- func (w *Wallet) AddAsset(issuer, assetId string, walletPassword *string) *Asset
- func (w *Wallet) AddRandomAccount(seed *string, walletPassword *string) *Account
- func (w *Wallet) AddTradingPair(asset1, asset2 *Asset, walletPassword *string) *TradingPair
- func (w *Wallet) AddWatchingAccount(pubkey string, walletPassword *string) *Account
- func (w *Wallet) AddressBook() []*Account
- func (w *Wallet) Assets() []*Asset
- func (w *Wallet) Bip39Mnemonic(walletPassword *string) (words []string)
- func (w *Wallet) ChangePassword(password, newPassword *string) bool
- func (w *Wallet) CheckIntegrity(walletPassword *string) bool
- func (w *Wallet) CheckPassword(walletPassword *string) bool
- func (w *Wallet) DeleteAccount(acc *Account) bool
- func (w *Wallet) DeleteAsset(a *Asset) bool
- func (w *Wallet) DeleteTradingPair(tp *TradingPair) bool
- func (w *Wallet) Description() string
- func (w *Wallet) ExportBase64() string
- func (w *Wallet) ExportBinary() []byte
- func (w *Wallet) FindAccountByDescription(desc string) *Account
- func (w *Wallet) FindAccountByPublicKey(pubkey string) *Account
- func (w *Wallet) FindAsset(issuer, assetId string) *Asset
- func (w *Wallet) FindAssetsByIssuer(issuer string) []*Asset
- func (w *Wallet) FindTradingPair(asset1, asset2 *Asset) *TradingPair
- func (w *Wallet) Flags() WalletFlags
- func (w *Wallet) GenerateAccount(walletPassword *string) *Account
- func (w *Wallet) GenerateBip39Seed(walletPassword *string, mnemonicPassword *string) bool
- func (w *Wallet) RecoverAccounts(walletPassword *string, maxGap uint16, fundedCheck func(adr string) bool)
- func (w *Wallet) SeedAccounts() []*Account
- func (w *Wallet) SetDescription(desc string, walletPassword *string) error
- func (w *Wallet) SetFlags(flags WalletFlags, walletPassword *string) bool
- func (w *Wallet) TradingPairs() []*TradingPair
- type WalletFlags
Constants ¶
const AccountTypeAddressBook = 4 // Account is an address book entry (public key only)
const AccountTypeRandom = 2 // Account is based on a randomly generated key
const AccountTypeSEP0005 = 1 // Account is SEP0005 derived from the BIP39 seed
const AccountTypeUndefined = 0 // Account type undefined
const AccountTypeWatching = 3 // Account has a public key only
const WalletFlagAll = WalletFlagSignDescription | WalletFlagSignAccounts | WalletFlagSignAccountMemo | WalletFlagSignAssets | WalletFlagSignTradingPairs
const WalletFlagSignAccountMemo = 1 << 2
const WalletFlagSignAccounts = 1 << 1
const WalletFlagSignAll = WalletFlagSignDescription | WalletFlagSignAccounts | WalletFlagSignAccountMemo | WalletFlagSignAssets | WalletFlagSignTradingPairs
const WalletFlagSignAssets = 1 << 3
const WalletFlagSignDescription = 1 << 0
const WalletFlagSignTradingPairs = 1 << 4
Variables ¶
var ErrorInvalidPassword = errors.New("invalid password")
error returned for invalid password
Functions ¶
func CheckAssetId ¶
CheckAssetId checks if given string is a valid asset id. If not valid returned error contains details about failed check.
func CheckDescription ¶
CheckDescription checks for valid wallet, account or asset description string. If given description is not valid returned error contains details about failed check.
func CheckMemoText ¶
CheckMemoText checks for valid transaction memo text. If given memo text is not valid returned error contains details about failed check.
func CheckMnemonicWord ¶
CheckMnemonicWord checks if given string is a valid mnemonic word. Can be used by applications to immediately check validity of entered mnemonic words for wallet recovery.
func CheckPrivateKey ¶
CheckPrivateKey checks if given string is a valid private account key (seed).
func CheckPublicKey ¶
CheckPublicKey checks if given string is a valid public account key.
func EraseByteBuffer ¶
func EraseByteBuffer(b []byte)
EraseByteBuffer wipes content of given byte buffer.
func SelfTest ¶
func SelfTest() error
SelfTest performs self test to ensure that hardware performs correct calculations. Failures are indicated by a non nil error. All wallet creation methods run this self test as well and will panic if it fails. This function should be called by an application first in order to gracefully handle hardware failures.
Types ¶
type Account ¶
type Account struct {
// contains filtered or unexported fields
}
func (*Account) ClearMemoId ¶
ClearMemoId clears memo id from account. walletPassword is required only if account and memo signing is selected in the wallet flags, otherwise it is ignored. Error is returned if an invalid wallet password was given.
func (*Account) Description ¶
Description returns description of account. Empty string is returned if no description is defined.
func (*Account) HasPrivateKey ¶
HasPrivateKey checks true if current account holds a private key.
func (*Account) IsAddressBookAccount ¶
IsAddressBookAccount checks if current account is an address book account..
func (*Account) IsOwnAccount ¶
IsOwnAccount checks if current account is an own account, i.e. of type generated, random or watching.
func (*Account) MemoId ¶
MemoId returns memo id of account. If no memo id is defined for current account, the boolean return value is false.
func (*Account) MemoText ¶
MemoText returns the optional memo text of account. Empty string is returned if no memo text is defined.
func (*Account) PrivateKey ¶
PrivateKey returns private key of account. Emptry string is returned if wallet password is not valid or current account does not hold a private key.
func (*Account) SetDescription ¶
SetDescription sets description on account. walletPassword is required only if account and description signing is selected in the wallet flags, otherwise it is ignored. Error is returned if given string does not pass the valid description check or an invalid wallet password was given.
func (*Account) SetMemoId ¶
SetMemoId sets memo id on account. walletPassword is required only if account and memo signing is selected in the wallet flags, otherwise it is ignored. Error is returned if an invalid wallet password was given.
func (*Account) SetMemoText ¶
type Asset ¶
type Asset struct {
// contains filtered or unexported fields
}
func (*Asset) Description ¶
Description returns description of asset. Empty string is returned if no description is defined.
func (*Asset) SetDescription ¶
SetDescription sets description on asset. walletPassword is required only if asset and description signing is selected in the wallet flags, otherwise it is ignored. Error is returned if given string does not pass the valid description check or an invalid wallet password was given.
func (*Asset) TradingPairs ¶
func (a *Asset) TradingPairs() []*TradingPair
TradingPairs returns slice with all trading pairs the refer to the current asset.
type TradingPair ¶
type TradingPair struct {
// contains filtered or unexported fields
}
func (*TradingPair) Asset1 ¶
func (tp *TradingPair) Asset1() *Asset
Asset1 returns first asset of trading pair. nil denotes native Lumen.
func (*TradingPair) Asset2 ¶
func (tp *TradingPair) Asset2() *Asset
Asset2 returns second asset of trading pair. nil denotes native Lumen.
func (*TradingPair) Description ¶
func (tp *TradingPair) Description() string
Description returns description of trading pair. Empty string is returned if no description is defined.
func (*TradingPair) SetDescription ¶
func (tp *TradingPair) SetDescription(desc string, walletPassword *string) error
SetDescription sets description on tarding pair. walletPassword is required only if trading pair and description signing is selected in the wallet flags, otherwise it is ignored. Error is returned if given string does not pass the valid description check or an invalid wallet password was given.
type Wallet ¶
type Wallet struct {
// contains filtered or unexported fields
}
func ImportBase64 ¶
ImportBase64 creates a new wallet from an exported ascii (base 64) serialization of the wallet content. This method can be used to restore a wallet from a permanent storage location. This method panics if the build-in self test fails (see method SelfTest()).
func ImportBinary ¶
ImportBinary creates a new wallet from an exported binary serialization of the wallet content. This method can be used to restore a wallet from a permanent storage location. This method panics if the build-in self test fails (see method SelfTest()).
func NewWallet ¶
func NewWallet(flags WalletFlags, password *string) *Wallet
NewWallet creates a new empty wallet, encrypted with given password. Each new wallet has an associated encrypted 256 bit entropy, which is the source for the mnemonic words list, i.e. the mnemonic word list is defined when a new wallet is created. This method panics if invalid wallet flags are given. This method panics if the build-in self test fails (see method SelfTest()).
func NewWalletFromMnemonic ¶
func NewWalletFromMnemonic(flags WalletFlags, walletPassword *string, mnemonic []string, mnemonicPassword *string) *Wallet
NewWalletFromMnemonic creates a new wallet from a given mnemonic word list and mnemonic password and encrypts it with given wallet password. This method is used to recover a wallet from a mnemonic word list and password. If the mnemonic word list is invalid, nil will be returned. An invalid mnemonic password is not detected so that it cannot be reported to the user. If a wrong mnemonic password is provided, another set of account seeds will be generated and the user will not see his funds. This method panics if the build-in self test fails (see method SelfTest()).
func (*Wallet) Accounts ¶
Accounts returns a slice containing all "own" accounts if current wallet, i.e. all but address book accounts.
func (*Wallet) AddAddressBookAccount ¶
AddAddressBookAccount adds an address book account and return a new Account object for it. Address book accounts just store the public account key. Address book accounts are treated as "foreign" accounts - in contrast to watching accounts. walletPassword is required only if public key signing is selected in the wallet flags, otherwise it is ignored. nil is returned if the given public key string is not valid or an invalid wallet password was given.
func (*Wallet) AddAsset ¶
AddAsset creates a new asset and returns a Asset object for it. walletPassword is required only if asset signing is selected in the wallet flags, otherwise it is ignored. nil is returned if the given issues string is not a valid public account key or if the given assetId is not valid.
func (*Wallet) AddRandomAccount ¶
AddRandomAccount adds a new account with given private key (seed) and returns a new Account object. The private key is stored encrypted. Application implementors should make the user aware that this type of account cannot be recovered with the mnemonic word list and password. nil is returend if the wallet password is invalid or an invald seed string was provided.
func (*Wallet) AddTradingPair ¶
func (w *Wallet) AddTradingPair(asset1, asset2 *Asset, walletPassword *string) *TradingPair
AddTradingPair adds a new trading pair to the wallet. If a trading pair for the given assets is already defined, the existing pair is returned. The native Lumen is represented by a nil asset. walletPassword is required only if asset signing is selected in the wallet flags, otherwise it is ignored. For following error conditions nil is returned: assets do not belong to current wallet, assets are identical, invalid wallet password
func (*Wallet) AddWatchingAccount ¶
AddWatchingAccount adds a watching account and return a new Account object for it. Watching accounts just store the public account key. Watching accounts are treated as "own" accounts - in contrast to address book accounts. walletPassword is required only if public key signing is selected in the wallet flags, otherwise it is ignored. nil is returned if the given public key string is not valid or an invalid wallet password was given.
func (*Wallet) AddressBook ¶
AddressBook returns a slice containing all address book accounts.
func (*Wallet) Bip39Mnemonic ¶
Bip39Mnemonic returns mnemonic word list (24 words) associated with the current wallet. After creating a new wallet this word list should be presented to the user.
func (*Wallet) ChangePassword ¶
ChangePassword changes the wallet password. false is returned only if the given wallet password is invalid.
func (*Wallet) CheckIntegrity ¶
CheckIntegrity verifies the consistency of the wallet data and ensures that the not encrypted data of the wallet has not been modified (e.g. by an attacker). Returns true on successful integrity verification, else false. If the given walletPassword is invalid, false will be returned as well.
func (*Wallet) CheckPassword ¶
CheckPassword checks if given wallet password is valid.
func (*Wallet) DeleteAccount ¶
DeleteAccount deletes given account. false is returned if given account does not belong to current wallet object.
func (*Wallet) DeleteAsset ¶
DeleteAsset deletes given asset from wallet. Returns true on success.
func (*Wallet) DeleteTradingPair ¶
func (w *Wallet) DeleteTradingPair(tp *TradingPair) bool
DeleteTradingPair deletes given tarding pair from the wallet. On success true is returned.
func (*Wallet) Description ¶
Description returns the optional wallet description.
func (*Wallet) ExportBase64 ¶
ExportBase64 creates an ascii (base 64) serialization of the wallet content, e.g. for permanent storage of the wallet on disk.
func (*Wallet) ExportBinary ¶
ExportBinary creates a binary serialization of the wallet content, e.g. for permanent storage of the wallet on disk.
func (*Wallet) FindAccountByDescription ¶
FindAccountByDescription returns first account matching given description string. Matching is performed case insensitive on sub string level.. If not matching account is found, nil is returned.
func (*Wallet) FindAccountByPublicKey ¶
FindAccountByPublicKey returns account object for given public account key. If not matching account is found, nil is returned.
func (*Wallet) FindAsset ¶
FindAsset returns asset object for given issues and asset id. nil is return if no matching asset is found.
func (*Wallet) FindAssetsByIssuer ¶
FindAssetsByIssuer returns a slice containing all assets that match the given issuer string.
func (*Wallet) FindTradingPair ¶
func (w *Wallet) FindTradingPair(asset1, asset2 *Asset) *TradingPair
FindTradingPair returns trading pair for given assets. Return nil of no trading pair is defined for given assets.
func (*Wallet) Flags ¶
func (w *Wallet) Flags() WalletFlags
Flags returns the currently set wallet flags.
func (*Wallet) GenerateAccount ¶
GenerateAccount generates a new account according to SEP-0005. The wallet password is required to decrypt the BIP39 seed. Before this method can be used, method GenerateBip39Seed() must have been called before once. nil is returned if GenerateBip39Seed() was not called before or the wallet password is not valid.
func (*Wallet) GenerateBip39Seed ¶
GenerateBip39Seed generates the seed used for key derivation (generated accounts). This method mus be called before the first call to GenerateAccount(). It uses the mnemonic word list, which is internally derived from the master seed (same as returned by Bip39Mnemonic()), and combines it with the given mnemonic password. The wallet password is required for decrypting and master seed and encrypting the generated key derivation seed (BIP39 seed).
func (*Wallet) RecoverAccounts ¶
func (w *Wallet) RecoverAccounts(walletPassword *string, maxGap uint16, fundedCheck func(adr string) bool)
RecoverAccounts can be used to recover accounts after a wallet was recovered from a mnemonic word list. It will generate accounts and check if they are funded via provided function fundedCheck(). fundedCheck() must be a functions that checks on the Stellar network if the given account is funded and returns true in case. maxGap defines the maximum number of unfunded accounts being accepted until the search stops.
func (*Wallet) SeedAccounts ¶
SeedAccounts returns a slice containing all accounts with a private key, i.e. generated and random accounts.
func (*Wallet) SetDescription ¶
SetDescription sets wallet description. walletPassword is required only if wallet flag WalletFlagSignDescription is set in order to sign the description text, otherwise it is ignored. Error is returned if given string does not pass the valid description check or an invalid wallet password was given.
func (*Wallet) SetFlags ¶
func (w *Wallet) SetFlags(flags WalletFlags, walletPassword *string) bool
SetFlags sets new wallet flags. walletPassword is required to re-build the signatures. This function panics if invalid wallet flags are given. Return false if an invalid wallet password was given.
func (*Wallet) TradingPairs ¶
func (w *Wallet) TradingPairs() []*TradingPair
TradingPairs returns a slice with all trading pairs of the wallet.
type WalletFlags ¶
type WalletFlags uint64