stellarwallet

package module
v0.0.0-...-4af0ed1 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 19 Imported by: 1

README

stellarwallet

Wallet API for in memory and on disk representation of Stellar accounts and assets supporting SEP-0005 key derivation.

Documentation

Index

Constants

View Source
const AccountTypeAddressBook = 4 // Account is an address book entry (public key only)
View Source
const AccountTypeRandom = 2 // Account is based on a randomly generated key
View Source
const AccountTypeSEP0005 = 1 // Account is SEP0005 derived from the BIP39 seed
View Source
const AccountTypeUndefined = 0 // Account type undefined
View Source
const AccountTypeWatching = 3 // Account has a public key only
View Source
const WalletFlagSignAccountMemo = 1 << 2
View Source
const WalletFlagSignAccounts = 1 << 1
View Source
const WalletFlagSignAssets = 1 << 3
View Source
const WalletFlagSignDescription = 1 << 0
View Source
const WalletFlagSignTradingPairs = 1 << 4

Variables

View Source
var ErrorInvalidPassword = errors.New("invalid password")

error returned for invalid password

Functions

func CheckAssetId

func CheckAssetId(s string) error

CheckAssetId checks if given string is a valid asset id. If not valid returned error contains details about failed check.

func CheckDescription

func CheckDescription(s string) error

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

func CheckMemoText(s string) error

CheckMemoText checks for valid transaction memo text. If given memo text is not valid returned error contains details about failed check.

func CheckMnemonicWord

func CheckMnemonicWord(s string) bool

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

func CheckPrivateKey(s *string) bool

CheckPrivateKey checks if given string is a valid private account key (seed).

func CheckPublicKey

func CheckPublicKey(s string) bool

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 EraseString

func EraseString(s *string)

EraseString wipes content of given string.

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

func (a *Account) ClearMemoId(walletPassword *string) error

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

func (a *Account) Description() string

Description returns description of account. Empty string is returned if no description is defined.

func (*Account) HasPrivateKey

func (a *Account) HasPrivateKey() bool

HasPrivateKey checks true if current account holds a private key.

func (*Account) IsAddressBookAccount

func (a *Account) IsAddressBookAccount() bool

IsAddressBookAccount checks if current account is an address book account..

func (*Account) IsOwnAccount

func (a *Account) IsOwnAccount() bool

IsOwnAccount checks if current account is an own account, i.e. of type generated, random or watching.

func (*Account) MemoId

func (a *Account) MemoId() (bool, uint64)

MemoId returns memo id of account. If no memo id is defined for current account, the boolean return value is false.

func (*Account) MemoText

func (a *Account) MemoText() string

MemoText returns the optional memo text of account. Empty string is returned if no memo text is defined.

func (*Account) PrivateKey

func (a *Account) PrivateKey(walletPassword *string) string

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) PublicKey

func (a *Account) PublicKey() string

PublicKey returns public key of account.

func (*Account) SetDescription

func (a *Account) SetDescription(desc string, walletPassword *string) error

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

func (a *Account) SetMemoId(memo uint64, walletPassword *string) error

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

func (a *Account) SetMemoText(memo string, walletPassword *string) error

func (*Account) Type

func (a *Account) Type() uint16

Type returns account type.

type Asset

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

func (*Asset) AssetId

func (a *Asset) AssetId() string

Returns asset ID (aka code).

func (*Asset) Description

func (a *Asset) Description() string

Description returns description of asset. Empty string is returned if no description is defined.

func (*Asset) Issuer

func (a *Asset) Issuer() string

Returns issuer of asset.

func (*Asset) SetDescription

func (a *Asset) SetDescription(desc string, walletPassword *string) error

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

func ImportBase64(data string) (w *Wallet, err error)

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

func ImportBinary(buf []byte) (w *Wallet, err error)

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

func (w *Wallet) Accounts() []*Account

Accounts returns a slice containing all "own" accounts if current wallet, i.e. all but address book accounts.

func (*Wallet) AddAddressBookAccount

func (w *Wallet) AddAddressBookAccount(pubkey string, walletPassword *string) *Account

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

func (w *Wallet) AddAsset(issuer, assetId string, walletPassword *string) *Asset

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

func (w *Wallet) AddRandomAccount(seed *string, walletPassword *string) *Account

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

func (w *Wallet) AddWatchingAccount(pubkey string, walletPassword *string) *Account

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

func (w *Wallet) AddressBook() []*Account

AddressBook returns a slice containing all address book accounts.

func (*Wallet) Assets

func (w *Wallet) Assets() []*Asset

Assets returns a slice containing all assets of current wallet.

func (*Wallet) Bip39Mnemonic

func (w *Wallet) Bip39Mnemonic(walletPassword *string) (words []string)

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

func (w *Wallet) ChangePassword(password, newPassword *string) bool

ChangePassword changes the wallet password. false is returned only if the given wallet password is invalid.

func (*Wallet) CheckIntegrity

func (w *Wallet) CheckIntegrity(walletPassword *string) bool

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

func (w *Wallet) CheckPassword(walletPassword *string) bool

CheckPassword checks if given wallet password is valid.

func (*Wallet) DeleteAccount

func (w *Wallet) DeleteAccount(acc *Account) bool

DeleteAccount deletes given account. false is returned if given account does not belong to current wallet object.

func (*Wallet) DeleteAsset

func (w *Wallet) DeleteAsset(a *Asset) bool

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

func (w *Wallet) Description() string

Description returns the optional wallet description.

func (*Wallet) ExportBase64

func (w *Wallet) ExportBase64() string

ExportBase64 creates an ascii (base 64) serialization of the wallet content, e.g. for permanent storage of the wallet on disk.

func (*Wallet) ExportBinary

func (w *Wallet) ExportBinary() []byte

ExportBinary creates a binary serialization of the wallet content, e.g. for permanent storage of the wallet on disk.

func (*Wallet) FindAccountByDescription

func (w *Wallet) FindAccountByDescription(desc string) *Account

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

func (w *Wallet) FindAccountByPublicKey(pubkey string) *Account

FindAccountByPublicKey returns account object for given public account key. If not matching account is found, nil is returned.

func (*Wallet) FindAsset

func (w *Wallet) FindAsset(issuer, assetId string) *Asset

FindAsset returns asset object for given issues and asset id. nil is return if no matching asset is found.

func (*Wallet) FindAssetsByIssuer

func (w *Wallet) FindAssetsByIssuer(issuer string) []*Asset

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

func (w *Wallet) GenerateAccount(walletPassword *string) *Account

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

func (w *Wallet) GenerateBip39Seed(walletPassword *string, mnemonicPassword *string) bool

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

func (w *Wallet) SeedAccounts() []*Account

SeedAccounts returns a slice containing all accounts with a private key, i.e. generated and random accounts.

func (*Wallet) SetDescription

func (w *Wallet) SetDescription(desc string, walletPassword *string) error

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

Jump to

Keyboard shortcuts

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