Documentation ¶
Index ¶
- Constants
- Variables
- func Contains[T comparable](container []T, element T, isEqual func(T, T) bool) bool
- func HaveSameElements[T comparable](a []T, b []T, isEqual func(T, T) bool) bool
- func SameAccounts(expected, real *Account) bool
- func SameAccountsIncludingPosition(expected, real *Account) bool
- func SameAccountsWithDifferentOperable(expected, real *Account, expectedOperableValue AccountOperable) bool
- func SameKeycards(expected, real *Keycard) bool
- func SameKeypairs(expected, real *Keypair) bool
- func SameKeypairsWithDifferentSyncedFrom(expected, real *Keypair, ignoreSyncedFrom bool, expectedSyncedFromValue string, ...) bool
- type Account
- type AccountOperable
- type AccountType
- type AccountsStorage
- type Database
- func (db *Database) AddressExists(address types.Address) (exists bool, err error)
- func (db *Database) AddressWasShown(address types.Address) error
- func (db *Database) CheckAndDeleteExpiredKeypairsAndAccounts(time uint64) error
- func (db *Database) Close() error
- func (db *Database) DB() *sql.DB
- func (db *Database) DeleteAllKeycardsWithKeyUID(keyUID string, clock uint64) (err error)
- func (db *Database) DeleteKeycard(kcUID string, clock uint64) (err error)
- func (db *Database) DeleteKeycardAccounts(kcUID string, accountAddresses []types.Address, clock uint64) (err error)
- func (db *Database) GetAccountByAddress(address types.Address) (*Account, error)
- func (db *Database) GetActiveAccounts() ([]*Account, error)
- func (db *Database) GetActiveKeypairs() ([]*Keypair, error)
- func (db *Database) GetActiveWatchOnlyAccounts() (res []*Account, err error)
- func (db *Database) GetAddresses() (rst []types.Address, err error)
- func (db *Database) GetAllAccounts() ([]*Account, error)
- func (db *Database) GetAllKeypairs() ([]*Keypair, error)
- func (db *Database) GetAllKnownKeycards() ([]*Keycard, error)
- func (db *Database) GetAllWatchOnlyAccounts() (res []*Account, err error)
- func (db *Database) GetChatAddress() (rst types.Address, err error)
- func (db *Database) GetClockOfLastAccountsPositionChange() (result uint64, err error)
- func (db *Database) GetKeycardByKeycardUID(keycardUID string) (*Keycard, error)
- func (db *Database) GetKeycardsWithSameKeyUID(keyUID string) ([]*Keycard, error)
- func (db *Database) GetKeypairByKeyUID(keyUID string) (*Keypair, error)
- func (db *Database) GetNodeConfig() (*params.NodeConfig, error)
- func (db *Database) GetNumOfAddressesToGenerateForKeypair(keyUID string) (uint64, error)
- func (db *Database) GetPath(address types.Address) (path string, err error)
- func (db *Database) GetPositionForNextNewAccount() (int64, error)
- func (db *Database) GetPositionForNextNewKeycard() (uint64, error)
- func (db *Database) GetProfileKeypair() (*Keypair, error)
- func (db *Database) GetWalletAddress() (rst types.Address, err error)
- func (db *Database) GetWalletAddresses() (rst []types.Address, err error)
- func (db *Database) IsAnyAccountPartiallyOrFullyOperableForKeyUID(keyUID string) (bool, error)
- func (db *Database) KeycardLocked(kcUID string, clock uint64) (err error)
- func (db *Database) KeycardUnlocked(kcUID string, clock uint64) (err error)
- func (db *Database) KeypairExists(keyUID string) (exists bool, err error)
- func (db *Database) MarkAccountFullyOperable(address types.Address) (err error)
- func (db *Database) MarkKeypairFullyOperable(keyUID string, clock uint64, updateKeypairClock bool) (err error)
- func (db *Database) MoveWalletAccount(fromPosition int64, toPosition int64, clock uint64) (err error)
- func (db *Database) RemoveAccount(address types.Address, clock uint64) error
- func (db *Database) RemoveKeypair(keyUID string, clock uint64) error
- func (db *Database) ResolveAccountsPositions(clock uint64) (err error)
- func (db *Database) ResolveSuggestedPathForKeypair(keyUID string) (suggestedPath string, err error)
- func (db *Database) SaveOrUpdateAccounts(accounts []*Account, updateKeypairClock bool) error
- func (db *Database) SaveOrUpdateKeycard(keycard Keycard, clock uint64, updateKeypairClock bool) error
- func (db *Database) SaveOrUpdateKeypair(keypair *Keypair) error
- func (db *Database) SetKeycardName(kcUID string, kpName string, clock uint64) (err error)
- func (db *Database) SetKeypairSyncedFrom(address types.Address, operable AccountOperable) (err error)
- func (db *Database) SetWalletAccountsPositions(accounts []*Account, clock uint64) (err error)
- func (db *Database) UpdateKeycardUID(oldKcUID string, newKcUID string, clock uint64) (err error)
- func (db *Database) UpdateKeypairName(keyUID string, name string, clock uint64, updateChatAccountName bool) error
- type Keycard
- type Keypair
- type KeypairType
Constants ¶
const ( SyncedFromBackup = "backup" // means a keypair is coming from backed up data ThirtyDaysInMilliseconds = 30 * 24 * 60 * 60 * 1000 )
const ( AccountNonOperable AccountOperable = "no" // an account is non operable it is not a keycard account and there is no keystore file for it and no keystore file for the address it is derived from AccountPartiallyOperable AccountOperable = "partially" // an account is partially operable if it is not a keycard account and there is created keystore file for the address it is derived from AccountFullyOperable AccountOperable = "fully" // an account is fully operable if it is not a keycard account and there is a keystore file for it ProdPreferredChainIDsDefault = "1:10:42161" TestPreferredChainIDsDefault = "5:420:421613" TestSepoliaPreferredChainIDsDefault = "11155111:11155420:421614" )
const (
// NodeConfigTag tag for a node configuration.
NodeConfigTag = "node_config"
)
Variables ¶
var ( ErrDbKeypairNotFound = errors.New("accounts: keypair is not found") ErrCannotRemoveProfileKeypair = errors.New("accounts: cannot remove profile keypair") ErrDbAccountNotFound = errors.New("accounts: account is not found") ErrCannotRemoveProfileAccount = errors.New("accounts: cannot remove profile account") ErrCannotRemoveDefaultWalletAccount = errors.New("accounts: cannot remove default wallet account") ErrAccountWrongPosition = errors.New("accounts: trying to set wrong position to account") ErrNotTheSameNumberOdAccountsToApplyReordering = errors.New("accounts: there is different number of accounts between received sync message and db accounts") ErrNotTheSameAccountsToApplyReordering = errors.New("accounts: there are differences between accounts in received sync message and db accounts") ErrMovingAccountToWrongPosition = errors.New("accounts: trying to move account to a wrong position") ErrKeypairDifferentAccountsKeyUID = errors.New("cannot store keypair with different accounts' key uid than keypair's key uid") ErrKeypairWithoutAccounts = errors.New("cannot store keypair without accounts") )
var (
ErrNoKeycardForPassedKeycardUID = errors.New("keycard: no keycard for the passed keycard uid")
)
Functions ¶
func Contains ¶ added in v0.161.6
func Contains[T comparable](container []T, element T, isEqual func(T, T) bool) bool
func HaveSameElements ¶ added in v0.161.6
func HaveSameElements[T comparable](a []T, b []T, isEqual func(T, T) bool) bool
func SameAccounts ¶ added in v0.152.2
func SameAccountsIncludingPosition ¶ added in v0.162.9
func SameAccountsWithDifferentOperable ¶ added in v0.152.2
func SameAccountsWithDifferentOperable(expected, real *Account, expectedOperableValue AccountOperable) bool
func SameKeycards ¶ added in v0.152.2
func SameKeypairs ¶ added in v0.152.2
func SameKeypairsWithDifferentSyncedFrom ¶ added in v0.152.2
func SameKeypairsWithDifferentSyncedFrom(expected, real *Keypair, ignoreSyncedFrom bool, expectedSyncedFromValue string, expectedOperableValue AccountOperable) bool
Types ¶
type Account ¶
type Account struct { Address types.Address `json:"address"` KeyUID string `json:"key-uid"` Wallet bool `json:"wallet"` AddressWasNotShown bool `json:"address-was-not-shown,omitempty"` Chat bool `json:"chat"` Type AccountType `json:"type,omitempty"` Path string `json:"path,omitempty"` PublicKey types.HexBytes `json:"public-key,omitempty"` Name string `json:"name"` Emoji string `json:"emoji"` ColorID common.CustomizationColor `json:"colorId,omitempty"` Hidden bool `json:"hidden"` Clock uint64 `json:"clock,omitempty"` Removed bool `json:"removed,omitempty"` Operable AccountOperable `json:"operable"` // describes an account's operability (check AccountOperable type constants for details) CreatedAt int64 `json:"createdAt"` Position int64 `json:"position"` ProdPreferredChainIDs string `json:"prodPreferredChainIds"` TestPreferredChainIDs string `json:"testPreferredChainIds"` }
func GetWatchOnlyAccountsForTest ¶ added in v0.152.2
func GetWatchOnlyAccountsForTest() []*Account
func (*Account) IsWalletAccountReadyForTransaction ¶ added in v0.171.21
Returns true if an account is a wallet account that is ready for sending transactions, otherwise returns false.
func (*Account) IsWalletNonWatchOnlyAccount ¶ added in v0.171.21
Returns true if an account is a wallet account that logged in user has a control over, otherwise returns false.
func (*Account) MarshalJSON ¶ added in v0.100.0
type AccountOperable ¶ added in v0.152.2
type AccountOperable string
func (AccountOperable) String ¶ added in v0.152.2
func (a AccountOperable) String() string
type AccountType ¶ added in v0.106.3
type AccountType string
const ( AccountTypeGenerated AccountType = "generated" AccountTypeKey AccountType = "key" AccountTypeSeed AccountType = "seed" AccountTypeWatch AccountType = "watch" )
func GetAccountTypeForKeypairType ¶ added in v0.161.2
func GetAccountTypeForKeypairType(kpType KeypairType) AccountType
func (AccountType) String ¶ added in v0.106.3
func (a AccountType) String() string
type AccountsStorage ¶ added in v0.179.27
type AccountsStorage interface { GetKeypairByKeyUID(keyUID string) (*Keypair, error) GetAccountByAddress(address types.Address) (*Account, error) AddressExists(address types.Address) (bool, error) }
TODO: implement clean full interface. This might require refactoring Database methods
type Database ¶
type Database struct { settings.DatabaseSettingsManager *notificationssettings.NotificationsSettings *walletsettings.WalletSettings // contains filtered or unexported fields }
Database sql wrapper for operations with browser objects.
func (*Database) AddressExists ¶
AddressExists returns true if given address is stored in database.
func (*Database) AddressWasShown ¶ added in v0.171.26
func (*Database) CheckAndDeleteExpiredKeypairsAndAccounts ¶ added in v0.162.13
func (*Database) DeleteAllKeycardsWithKeyUID ¶ added in v0.161.6
func (*Database) DeleteKeycard ¶ added in v0.161.6
func (*Database) DeleteKeycardAccounts ¶ added in v0.161.6
func (*Database) GetAccountByAddress ¶ added in v0.62.16
Returns account if it is not marked as removed.
func (*Database) GetActiveAccounts ¶ added in v0.162.13
Returns active accounts (excluding removed).
func (*Database) GetActiveKeypairs ¶ added in v0.162.13
Returns active keypairs (excluding removed and excluding removed accounts).
func (*Database) GetActiveWatchOnlyAccounts ¶ added in v0.162.13
Returns active watch only accounts (excluding removed).
func (*Database) GetAllAccounts ¶ added in v0.162.13
Returns all accounts (including removed).
func (*Database) GetAllKeypairs ¶ added in v0.162.13
Returns all keypairs (including removed and removed accounts).
func (*Database) GetAllKnownKeycards ¶ added in v0.161.6
func (*Database) GetAllWatchOnlyAccounts ¶ added in v0.162.13
Returns all watch only accounts (including removed).
func (*Database) GetChatAddress ¶
func (*Database) GetClockOfLastAccountsPositionChange ¶ added in v0.162.9
func (*Database) GetKeycardByKeycardUID ¶ added in v0.161.6
func (*Database) GetKeycardsWithSameKeyUID ¶ added in v0.161.6
func (*Database) GetKeypairByKeyUID ¶ added in v0.152.2
Returns keypair if it is not marked as removed and its accounts which are not marked as removed.
func (*Database) GetNodeConfig ¶ added in v0.38.4
func (db *Database) GetNodeConfig() (*params.NodeConfig, error)
NOTE: This should not be used to retrieve `Networks`. NetworkManager should be used instead, otherwise RPCURL will be empty
func (*Database) GetNumOfAddressesToGenerateForKeypair ¶ added in v0.178.0
func (*Database) GetPath ¶ added in v0.102.6
GetPath returns true if account with given address was recently key and doesn't have a key yet
func (*Database) GetPositionForNextNewAccount ¶ added in v0.161.2
func (*Database) GetPositionForNextNewKeycard ¶ added in v0.161.6
func (*Database) GetProfileKeypair ¶ added in v0.166.1
func (*Database) GetWalletAddress ¶
func (*Database) GetWalletAddresses ¶ added in v0.40.0
func (*Database) IsAnyAccountPartiallyOrFullyOperableForKeyUID ¶ added in v0.161.2
func (*Database) KeycardLocked ¶ added in v0.161.6
func (*Database) KeycardUnlocked ¶ added in v0.161.6
func (*Database) KeypairExists ¶ added in v0.161.6
KeypairExists returns true if given address is stored in database.
func (*Database) MarkAccountFullyOperable ¶ added in v0.166.1
func (*Database) MarkKeypairFullyOperable ¶ added in v0.163.4
func (db *Database) MarkKeypairFullyOperable(keyUID string, clock uint64, updateKeypairClock bool) (err error)
Basically this function should not update the clock, cause it marks keypair/accounts locally. But... we need to cover the case when user recovers a Status account from waku, then pairs another device via local pairing and then imports seed/private key for the non profile keypair on one of those two devices to make that keypair fully operable. In that case we need to inform other device about the change, that other device may offer other options for importing that keypair on it. If the clock is set to -1, do not update it.
func (*Database) MoveWalletAccount ¶ added in v0.162.9
func (db *Database) MoveWalletAccount(fromPosition int64, toPosition int64, clock uint64) (err error)
Moves wallet account fromPosition to toPosition.
func (*Database) RemoveAccount ¶ added in v0.162.13
func (*Database) RemoveKeypair ¶ added in v0.162.13
func (*Database) ResolveAccountsPositions ¶ added in v0.162.9
Updates positions of accounts respecting current order.
func (*Database) ResolveSuggestedPathForKeypair ¶ added in v0.178.0
func (*Database) SaveOrUpdateAccounts ¶ added in v0.152.2
Saves accounts, if an account already exists, it will be updated.
func (*Database) SaveOrUpdateKeycard ¶ added in v0.161.6
func (*Database) SaveOrUpdateKeypair ¶ added in v0.152.2
Saves a keypair and its accounts, if a keypair with `key_uid` already exists, it will be updated, if any of its accounts exists it will be updated as well, otherwise it will be added. Since keypair type contains `Keycards` as well, they are excluded from the saving/updating this way regardless they are set or not.
func (*Database) SetKeycardName ¶ added in v0.161.6
func (*Database) SetKeypairSyncedFrom ¶ added in v0.163.4
func (db *Database) SetKeypairSyncedFrom(address types.Address, operable AccountOperable) (err error)
This function should not update the clock, cause it marks a keypair locally.
func (*Database) SetWalletAccountsPositions ¶ added in v0.162.9
Sets positions for passed accounts.
func (*Database) UpdateKeycardUID ¶ added in v0.161.6
type Keycard ¶ added in v0.152.2
type Keycard struct { KeycardUID string `json:"keycard-uid"` KeycardName string `json:"keycard-name"` KeycardLocked bool `json:"keycard-locked"` AccountsAddresses []types.Address `json:"accounts-addresses"` KeyUID string `json:"key-uid"` Position uint64 }
func GetKeycardForSeedImportedKeypair1ForTest ¶ added in v0.152.2
func GetKeycardForSeedImportedKeypair1ForTest() *Keycard
func GetKeycardForSeedImportedKeypair2ForTest ¶ added in v0.152.2
func GetKeycardForSeedImportedKeypair2ForTest() *Keycard
func GetProfileKeycardForTest ¶ added in v0.152.2
func GetProfileKeycardForTest() *Keycard
func (*Keycard) FromSyncKeycard ¶ added in v0.152.2
func (kp *Keycard) FromSyncKeycard(kc *protobuf.SyncKeycard)
func (*Keycard) ToSyncKeycard ¶ added in v0.152.2
func (kp *Keycard) ToSyncKeycard() *protobuf.SyncKeycard
type Keypair ¶ added in v0.152.2
type Keypair struct { KeyUID string `json:"key-uid"` Name string `json:"name"` Type KeypairType `json:"type"` DerivedFrom string `json:"derived-from"` LastUsedDerivationIndex uint64 `json:"last-used-derivation-index,omitempty"` SyncedFrom string `json:"synced-from,omitempty"` // keeps an info which device this keypair is added from can be one of two values defined in constants or device name (custom) Clock uint64 `json:"clock,omitempty"` Accounts []*Account `json:"accounts,omitempty"` Keycards []*Keycard `json:"keycards,omitempty"` Removed bool `json:"removed,omitempty"` }
func GetPrivKeyImportedKeypairForTest ¶ added in v0.152.2
func GetPrivKeyImportedKeypairForTest() *Keypair
func GetProfileKeypairForTest ¶ added in v0.152.2
func GetSeedImportedKeypair1ForTest ¶ added in v0.152.2
func GetSeedImportedKeypair1ForTest() *Keypair
func GetSeedImportedKeypair2ForTest ¶ added in v0.152.2
func GetSeedImportedKeypair2ForTest() *Keypair
func (*Keypair) CopyKeypair ¶ added in v0.152.2
func (*Keypair) GetChatPublicKey ¶ added in v0.154.2
func (*Keypair) MarshalJSON ¶ added in v0.152.2
func (*Keypair) MigratedToKeycard ¶ added in v0.166.3
func (*Keypair) Operability ¶ added in v0.166.3
func (a *Keypair) Operability() AccountOperable
Returns operability of a keypair: - if any of keypair's account is not operable, then a keyapir is considered as non operable - if any of keypair's account is partially operable, then a keyapir is considered as partially operable - if all accounts are fully operable, then a keyapir is considered as fully operable
type KeypairType ¶ added in v0.152.2
type KeypairType string
const ( KeypairTypeProfile KeypairType = "profile" KeypairTypeKey KeypairType = "key" KeypairTypeSeed KeypairType = "seed" )
func (KeypairType) String ¶ added in v0.152.2
func (a KeypairType) String() string