accounts

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SyncedFromBackup         = "backup" // means a keypair is coming from backed up data
	ThirtyDaysInMilliseconds = 30 * 24 * 60 * 60 * 1000
)
View Source
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"
)
View Source
const (
	// NodeConfigTag tag for a node configuration.
	NodeConfigTag = "node_config"
)

Variables

View Source
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")
)
View Source
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 SameAccounts(expected, real *Account) bool

func SameAccountsIncludingPosition added in v0.162.9

func SameAccountsIncludingPosition(expected, real *Account) bool

func SameAccountsWithDifferentOperable added in v0.152.2

func SameAccountsWithDifferentOperable(expected, real *Account, expectedOperableValue AccountOperable) bool

func SameKeycards added in v0.152.2

func SameKeycards(expected, real *Keycard) bool

func SameKeypairs added in v0.152.2

func SameKeypairs(expected, real *Keypair) bool

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

func (a *Account) IsWalletAccountReadyForTransaction() bool

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

func (a *Account) IsWalletNonWatchOnlyAccount() bool

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

func (a *Account) MarshalJSON() ([]byte, error)

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 NewDB

func NewDB(db *sql.DB) (*Database, error)

NewDB returns a new instance of *Database

func (*Database) AddressExists

func (db *Database) AddressExists(address types.Address) (exists bool, err error)

AddressExists returns true if given address is stored in database.

func (*Database) AddressWasShown added in v0.171.26

func (db *Database) AddressWasShown(address types.Address) error

func (*Database) CheckAndDeleteExpiredKeypairsAndAccounts added in v0.162.13

func (db *Database) CheckAndDeleteExpiredKeypairsAndAccounts(time uint64) error

func (*Database) Close

func (db *Database) Close() error

Close closes database.

func (*Database) DB added in v0.93.2

func (db *Database) DB() *sql.DB

DB Gets db sql.DB

func (*Database) DeleteAllKeycardsWithKeyUID added in v0.161.6

func (db *Database) DeleteAllKeycardsWithKeyUID(keyUID string, clock uint64) (err error)

func (*Database) DeleteKeycard added in v0.161.6

func (db *Database) DeleteKeycard(kcUID string, clock uint64) (err error)

func (*Database) DeleteKeycardAccounts added in v0.161.6

func (db *Database) DeleteKeycardAccounts(kcUID string, accountAddresses []types.Address, clock uint64) (err error)

func (*Database) GetAccountByAddress added in v0.62.16

func (db *Database) GetAccountByAddress(address types.Address) (*Account, error)

Returns account if it is not marked as removed.

func (*Database) GetActiveAccounts added in v0.162.13

func (db *Database) GetActiveAccounts() ([]*Account, error)

Returns active accounts (excluding removed).

func (*Database) GetActiveKeypairs added in v0.162.13

func (db *Database) GetActiveKeypairs() ([]*Keypair, error)

Returns active keypairs (excluding removed and excluding removed accounts).

func (*Database) GetActiveWatchOnlyAccounts added in v0.162.13

func (db *Database) GetActiveWatchOnlyAccounts() (res []*Account, err error)

Returns active watch only accounts (excluding removed).

func (*Database) GetAddresses

func (db *Database) GetAddresses() (rst []types.Address, err error)

func (*Database) GetAllAccounts added in v0.162.13

func (db *Database) GetAllAccounts() ([]*Account, error)

Returns all accounts (including removed).

func (*Database) GetAllKeypairs added in v0.162.13

func (db *Database) GetAllKeypairs() ([]*Keypair, error)

Returns all keypairs (including removed and removed accounts).

func (*Database) GetAllKnownKeycards added in v0.161.6

func (db *Database) GetAllKnownKeycards() ([]*Keycard, error)

func (*Database) GetAllWatchOnlyAccounts added in v0.162.13

func (db *Database) GetAllWatchOnlyAccounts() (res []*Account, err error)

Returns all watch only accounts (including removed).

func (*Database) GetChatAddress

func (db *Database) GetChatAddress() (rst types.Address, err error)

func (*Database) GetClockOfLastAccountsPositionChange added in v0.162.9

func (db *Database) GetClockOfLastAccountsPositionChange() (result uint64, err error)

func (*Database) GetKeycardByKeycardUID added in v0.161.6

func (db *Database) GetKeycardByKeycardUID(keycardUID string) (*Keycard, error)

func (*Database) GetKeycardsWithSameKeyUID added in v0.161.6

func (db *Database) GetKeycardsWithSameKeyUID(keyUID string) ([]*Keycard, error)

func (*Database) GetKeypairByKeyUID added in v0.152.2

func (db *Database) GetKeypairByKeyUID(keyUID string) (*Keypair, error)

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 (db *Database) GetNumOfAddressesToGenerateForKeypair(keyUID string) (uint64, error)

func (*Database) GetPath added in v0.102.6

func (db *Database) GetPath(address types.Address) (path string, err error)

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 (db *Database) GetPositionForNextNewAccount() (int64, error)

func (*Database) GetPositionForNextNewKeycard added in v0.161.6

func (db *Database) GetPositionForNextNewKeycard() (uint64, error)

func (*Database) GetProfileKeypair added in v0.166.1

func (db *Database) GetProfileKeypair() (*Keypair, error)

func (*Database) GetWalletAddress

func (db *Database) GetWalletAddress() (rst types.Address, err error)

func (*Database) GetWalletAddresses added in v0.40.0

func (db *Database) GetWalletAddresses() (rst []types.Address, err error)

func (*Database) IsAnyAccountPartiallyOrFullyOperableForKeyUID added in v0.161.2

func (db *Database) IsAnyAccountPartiallyOrFullyOperableForKeyUID(keyUID string) (bool, error)

func (*Database) KeycardLocked added in v0.161.6

func (db *Database) KeycardLocked(kcUID string, clock uint64) (err error)

func (*Database) KeycardUnlocked added in v0.161.6

func (db *Database) KeycardUnlocked(kcUID string, clock uint64) (err error)

func (*Database) KeypairExists added in v0.161.6

func (db *Database) KeypairExists(keyUID string) (exists bool, err error)

KeypairExists returns true if given address is stored in database.

func (*Database) MarkAccountFullyOperable added in v0.166.1

func (db *Database) MarkAccountFullyOperable(address types.Address) (err error)

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 (db *Database) RemoveAccount(address types.Address, clock uint64) error

func (*Database) RemoveKeypair added in v0.162.13

func (db *Database) RemoveKeypair(keyUID string, clock uint64) error

func (*Database) ResolveAccountsPositions added in v0.162.9

func (db *Database) ResolveAccountsPositions(clock uint64) (err error)

Updates positions of accounts respecting current order.

func (*Database) ResolveSuggestedPathForKeypair added in v0.178.0

func (db *Database) ResolveSuggestedPathForKeypair(keyUID string) (suggestedPath string, err error)

func (*Database) SaveOrUpdateAccounts added in v0.152.2

func (db *Database) SaveOrUpdateAccounts(accounts []*Account, updateKeypairClock bool) error

Saves accounts, if an account already exists, it will be updated.

func (*Database) SaveOrUpdateKeycard added in v0.161.6

func (db *Database) SaveOrUpdateKeycard(keycard Keycard, clock uint64, updateKeypairClock bool) error

func (*Database) SaveOrUpdateKeypair added in v0.152.2

func (db *Database) SaveOrUpdateKeypair(keypair *Keypair) error

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 (db *Database) SetKeycardName(kcUID string, kpName string, clock uint64) (err error)

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

func (db *Database) SetWalletAccountsPositions(accounts []*Account, clock uint64) (err error)

Sets positions for passed accounts.

func (*Database) UpdateKeycardUID added in v0.161.6

func (db *Database) UpdateKeycardUID(oldKcUID string, newKcUID string, clock uint64) (err error)

func (*Database) UpdateKeypairName added in v0.152.2

func (db *Database) UpdateKeypairName(keyUID string, name string, clock uint64, updateChatAccountName bool) error

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 GetProfileKeypairForTest(includeChatAccount bool, includeDefaultWalletAccount bool, includeAdditionalAccounts bool) *Keypair

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 (a *Keypair) CopyKeypair() *Keypair

func (*Keypair) GetChatPublicKey added in v0.154.2

func (a *Keypair) GetChatPublicKey() types.HexBytes

func (*Keypair) MarshalJSON added in v0.152.2

func (a *Keypair) MarshalJSON() ([]byte, error)

func (*Keypair) MigratedToKeycard added in v0.166.3

func (a *Keypair) MigratedToKeycard() bool

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

Jump to

Keyboard shortcuts

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