chore: `keypairs` package which actually refers to keycards is renamed to `keycards` package
This commit renames few api endpoints: - old `AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded` renamed to `AddKeycardOrAddAccountsIfKeycardIsAdded` - old `GetAllMigratedKeyPairs` renamed to `GetAllKnownKeycardsGroupedByKeyUID` - old `GetMigratedKeyPairByKeyUID` renamed to `GetKeycardByKeyUID` - old `DeleteKeypair` renamed to `DeleteAllKeycardsWithKeyUID`
This commit is contained in:
parent
acad6e4958
commit
189c7a6919
|
@ -934,9 +934,9 @@ func TestConvertAccount(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Check that there is no registered keycards
|
||||
keycardKeyPairs, err := db.GetMigratedKeyPairByKeyUID(genAccInfo.KeyUID)
|
||||
keycards, err := db.GetKeycardByKeyUID(genAccInfo.KeyUID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 0, len(keycardKeyPairs))
|
||||
require.Equal(t, 0, len(keycards))
|
||||
|
||||
// Converting to a keycard account
|
||||
err = backend.ConvertToKeycardAccount(keycardAccount, keycardSettings, keycardUID, password, keycardPassword)
|
||||
|
@ -961,9 +961,9 @@ func TestConvertAccount(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Check that there is a registered keycard
|
||||
keycardKeyPairs, err = db1.GetMigratedKeyPairByKeyUID(genAccInfo.KeyUID)
|
||||
keycards, err = db1.GetKeycardByKeyUID(genAccInfo.KeyUID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(keycardKeyPairs))
|
||||
require.Equal(t, 1, len(keycards))
|
||||
|
||||
b1 := NewGethStatusBackend()
|
||||
require.NoError(t, b1.OpenAccounts())
|
||||
|
@ -994,9 +994,9 @@ func TestConvertAccount(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Check that there is no registered keycards
|
||||
keycardKeyPairs, err = db2.GetMigratedKeyPairByKeyUID(genAccInfo.KeyUID)
|
||||
keycards, err = db2.GetKeycardByKeyUID(genAccInfo.KeyUID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 0, len(keycardKeyPairs))
|
||||
require.Equal(t, 0, len(keycards))
|
||||
|
||||
b2 := NewGethStatusBackend()
|
||||
require.NoError(t, b2.OpenAccounts())
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
"github.com/status-im/status-go/logutils"
|
||||
"github.com/status-im/status-go/multiaccounts"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/multiaccounts/keypairs"
|
||||
"github.com/status-im/status-go/multiaccounts/keycards"
|
||||
"github.com/status-im/status-go/multiaccounts/settings"
|
||||
"github.com/status-im/status-go/node"
|
||||
"github.com/status-im/status-go/nodecfg"
|
||||
|
@ -643,7 +643,7 @@ func (b *GethStatusBackend) ConvertToKeycardAccount(account multiaccounts.Accoun
|
|||
return err
|
||||
}
|
||||
|
||||
kp := keypairs.KeyPair{
|
||||
kc := keycards.Keycard{
|
||||
KeycardUID: keycardUID,
|
||||
KeycardName: displayName,
|
||||
KeycardLocked: false,
|
||||
|
@ -652,14 +652,14 @@ func (b *GethStatusBackend) ConvertToKeycardAccount(account multiaccounts.Accoun
|
|||
}
|
||||
|
||||
for _, acc := range relatedAccounts {
|
||||
kp.AccountsAddresses = append(kp.AccountsAddresses, acc.Address)
|
||||
kc.AccountsAddresses = append(kc.AccountsAddresses, acc.Address)
|
||||
}
|
||||
addedKc, _, err := accountDB.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(kp)
|
||||
addedKc, _, err := accountDB.AddKeycardOrAddAccountsIfKeycardIsAdded(kc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !addedKc {
|
||||
return errors.New("couldn't register a keypair to keycards table")
|
||||
return errors.New("couldn't register a keycard to keycards table")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -688,7 +688,7 @@ func (b *GethStatusBackend) ConvertToKeycardAccount(account multiaccounts.Accoun
|
|||
return err
|
||||
}
|
||||
|
||||
// We need to delete all accounts for the keypair which is being migrated
|
||||
// We need to delete all accounts for the Keycard which is being added
|
||||
for _, acc := range relatedAccounts {
|
||||
err = b.accountManager.DeleteAccount(acc.Address)
|
||||
if err != nil {
|
||||
|
@ -912,7 +912,7 @@ func (b *GethStatusBackend) ConvertToRegularAccount(mnemonic string, currPasswor
|
|||
return err
|
||||
}
|
||||
|
||||
err = db.DeleteKeypair(accountInfo.KeyUID)
|
||||
err = db.DeleteAllKeycardsWithKeyUID(accountInfo.KeyUID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/multiaccounts/errors"
|
||||
"github.com/status-im/status-go/multiaccounts/keypairs"
|
||||
"github.com/status-im/status-go/multiaccounts/keycards"
|
||||
"github.com/status-im/status-go/multiaccounts/settings"
|
||||
notificationssettings "github.com/status-im/status-go/multiaccounts/settings_notifications"
|
||||
sociallinkssettings "github.com/status-im/status-go/multiaccounts/settings_social_links"
|
||||
|
@ -112,7 +112,7 @@ type Database struct {
|
|||
*settings.Database
|
||||
*notificationssettings.NotificationsSettings
|
||||
*sociallinkssettings.SocialLinksSettings
|
||||
*keypairs.KeyPairs
|
||||
*keycards.Keycards
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ func NewDB(db *sql.DB) (*Database, error) {
|
|||
}
|
||||
sn := notificationssettings.NewNotificationsSettings(db)
|
||||
ssl := sociallinkssettings.NewSocialLinksSettings(db)
|
||||
kp := keypairs.NewKeyPairs(db)
|
||||
kp := keycards.NewKeycards(db)
|
||||
|
||||
err = updateKeypairNameAndLastDerivationIndexIfNeeded(db)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package keypairs
|
||||
package keycards
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
var errDbTransactionIsNil = errors.New("keycard: database transaction is nil")
|
||||
|
||||
type KeyPair struct {
|
||||
type Keycard struct {
|
||||
KeycardUID string `json:"keycard-uid"`
|
||||
KeycardName string `json:"keycard-name"`
|
||||
KeycardLocked bool `json:"keycard-locked"`
|
||||
|
@ -24,10 +24,10 @@ type KeyPair struct {
|
|||
type KeycardAction struct {
|
||||
Action string `json:"action"`
|
||||
OldKeycardUID string `json:"old-keycard-uid,omitempty"`
|
||||
Keycard *KeyPair `json:"keycard"`
|
||||
Keycard *Keycard `json:"keycard"`
|
||||
}
|
||||
|
||||
func (kp *KeyPair) ToSyncKeycard() *protobuf.SyncKeycard {
|
||||
func (kp *Keycard) ToSyncKeycard() *protobuf.SyncKeycard {
|
||||
kc := &protobuf.SyncKeycard{
|
||||
Uid: kp.KeycardUID,
|
||||
Name: kp.KeycardName,
|
||||
|
@ -43,7 +43,7 @@ func (kp *KeyPair) ToSyncKeycard() *protobuf.SyncKeycard {
|
|||
return kc
|
||||
}
|
||||
|
||||
func (kp *KeyPair) FromSyncKeycard(kc *protobuf.SyncKeycard) {
|
||||
func (kp *Keycard) FromSyncKeycard(kc *protobuf.SyncKeycard) {
|
||||
kp.KeycardUID = kc.Uid
|
||||
kp.KeycardName = kc.Name
|
||||
kp.KeycardLocked = kc.Locked
|
||||
|
@ -62,12 +62,12 @@ func removeElementAtIndex[T any](s []T, index int) []T {
|
|||
return append(s[:index], s[index+1:]...)
|
||||
}
|
||||
|
||||
type KeyPairs struct {
|
||||
type Keycards struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewKeyPairs(db *sql.DB) *KeyPairs {
|
||||
return &KeyPairs{
|
||||
func NewKeycards(db *sql.DB) *Keycards {
|
||||
return &Keycards{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
@ -81,46 +81,46 @@ func containsAddress(addresses []types.Address, address types.Address) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) processResult(rows *sql.Rows, groupByKeycard bool) ([]*KeyPair, error) {
|
||||
keyPairs := []*KeyPair{}
|
||||
func (kp *Keycards) processResult(rows *sql.Rows, groupByKeycard bool) ([]*Keycard, error) {
|
||||
keycards := []*Keycard{}
|
||||
for rows.Next() {
|
||||
keyPair := &KeyPair{}
|
||||
keycard := &Keycard{}
|
||||
addr := types.Address{}
|
||||
err := rows.Scan(&keyPair.KeycardUID, &keyPair.KeycardName, &keyPair.KeycardLocked, &addr, &keyPair.KeyUID,
|
||||
&keyPair.LastUpdateClock)
|
||||
err := rows.Scan(&keycard.KeycardUID, &keycard.KeycardName, &keycard.KeycardLocked, &addr, &keycard.KeyUID,
|
||||
&keycard.LastUpdateClock)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
foundAtIndex := -1
|
||||
for i := range keyPairs {
|
||||
for i := range keycards {
|
||||
if groupByKeycard {
|
||||
if keyPairs[i].KeycardUID == keyPair.KeycardUID {
|
||||
if keycards[i].KeycardUID == keycard.KeycardUID {
|
||||
foundAtIndex = i
|
||||
break
|
||||
}
|
||||
} else {
|
||||
if keyPairs[i].KeyUID == keyPair.KeyUID {
|
||||
if keycards[i].KeyUID == keycard.KeyUID {
|
||||
foundAtIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if foundAtIndex == -1 {
|
||||
keyPair.AccountsAddresses = append(keyPair.AccountsAddresses, addr)
|
||||
keyPairs = append(keyPairs, keyPair)
|
||||
keycard.AccountsAddresses = append(keycard.AccountsAddresses, addr)
|
||||
keycards = append(keycards, keycard)
|
||||
} else {
|
||||
if containsAddress(keyPairs[foundAtIndex].AccountsAddresses, addr) {
|
||||
if containsAddress(keycards[foundAtIndex].AccountsAddresses, addr) {
|
||||
continue
|
||||
}
|
||||
keyPairs[foundAtIndex].AccountsAddresses = append(keyPairs[foundAtIndex].AccountsAddresses, addr)
|
||||
keycards[foundAtIndex].AccountsAddresses = append(keycards[foundAtIndex].AccountsAddresses, addr)
|
||||
}
|
||||
}
|
||||
|
||||
return keyPairs, nil
|
||||
return keycards, nil
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) getAllRows(groupByKeycard bool) ([]*KeyPair, error) {
|
||||
func (kp *Keycards) getAllRows(groupByKeycard bool) ([]*Keycard, error) {
|
||||
rows, err := kp.db.Query(`
|
||||
SELECT
|
||||
k.keycard_uid,
|
||||
|
@ -146,15 +146,15 @@ func (kp *KeyPairs) getAllRows(groupByKeycard bool) ([]*KeyPair, error) {
|
|||
return kp.processResult(rows, groupByKeycard)
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) GetAllKnownKeycards() ([]*KeyPair, error) {
|
||||
func (kp *Keycards) GetAllKnownKeycards() ([]*Keycard, error) {
|
||||
return kp.getAllRows(true)
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) GetAllMigratedKeyPairs() ([]*KeyPair, error) {
|
||||
func (kp *Keycards) GetAllKnownKeycardsGroupedByKeyUID() ([]*Keycard, error) {
|
||||
return kp.getAllRows(false)
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) GetMigratedKeyPairByKeyUID(keyUID string) ([]*KeyPair, error) {
|
||||
func (kp *Keycards) GetKeycardByKeyUID(keyUID string) ([]*Keycard, error) {
|
||||
rows, err := kp.db.Query(`
|
||||
SELECT
|
||||
k.keycard_uid,
|
||||
|
@ -182,7 +182,7 @@ func (kp *KeyPairs) GetMigratedKeyPairByKeyUID(keyUID string) ([]*KeyPair, error
|
|||
return kp.processResult(rows, false)
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) startTransactionAndCheckIfNeedToProceed(kcUID string, clock uint64) (tx *sql.Tx, proceed bool, err error) {
|
||||
func (kp *Keycards) startTransactionAndCheckIfNeedToProceed(kcUID string, clock uint64) (tx *sql.Tx, proceed bool, err error) {
|
||||
tx, err = kp.db.Begin()
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
|
@ -196,7 +196,7 @@ func (kp *KeyPairs) startTransactionAndCheckIfNeedToProceed(kcUID string, clock
|
|||
return tx, dbLastUpdateClock <= clock, nil
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) setLastUpdateClock(tx *sql.Tx, kcUID string, clock uint64) (err error) {
|
||||
func (kp *Keycards) setLastUpdateClock(tx *sql.Tx, kcUID string, clock uint64) (err error) {
|
||||
if tx == nil {
|
||||
return errDbTransactionIsNil
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ func (kp *KeyPairs) setLastUpdateClock(tx *sql.Tx, kcUID string, clock uint64) (
|
|||
return err
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) getAccountsForKeycard(tx *sql.Tx, kcUID string) ([]types.Address, error) {
|
||||
func (kp *Keycards) getAccountsForKeycard(tx *sql.Tx, kcUID string) ([]types.Address, error) {
|
||||
var accountAddresses []types.Address
|
||||
if tx == nil {
|
||||
return accountAddresses, errDbTransactionIsNil
|
||||
|
@ -237,7 +237,7 @@ func (kp *KeyPairs) getAccountsForKeycard(tx *sql.Tx, kcUID string) ([]types.Add
|
|||
return accountAddresses, nil
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) addAccounts(tx *sql.Tx, kcUID string, accountsAddresses []types.Address) (err error) {
|
||||
func (kp *Keycards) addAccounts(tx *sql.Tx, kcUID string, accountsAddresses []types.Address) (err error) {
|
||||
if tx == nil {
|
||||
return errDbTransactionIsNil
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ func (kp *KeyPairs) addAccounts(tx *sql.Tx, kcUID string, accountsAddresses []ty
|
|||
return nil
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) deleteKeycard(tx *sql.Tx, kcUID string) (err error) {
|
||||
func (kp *Keycards) deleteKeycard(tx *sql.Tx, kcUID string) (err error) {
|
||||
if tx == nil {
|
||||
return errDbTransactionIsNil
|
||||
}
|
||||
|
@ -292,8 +292,8 @@ func (kp *KeyPairs) deleteKeycard(tx *sql.Tx, kcUID string) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(keyPair KeyPair) (addedKc bool, addedAccs bool, err error) {
|
||||
tx, proceed, err := kp.startTransactionAndCheckIfNeedToProceed(keyPair.KeycardUID, keyPair.LastUpdateClock)
|
||||
func (kp *Keycards) AddKeycardOrAddAccountsIfKeycardIsAdded(keycard Keycard) (addedKc bool, addedAccs bool, err error) {
|
||||
tx, proceed, err := kp.startTransactionAndCheckIfNeedToProceed(keycard.KeycardUID, keycard.LastUpdateClock)
|
||||
defer func() {
|
||||
if err == nil {
|
||||
err = tx.Commit()
|
||||
|
@ -317,29 +317,29 @@ func (kp *KeyPairs) AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(keyPair KeyP
|
|||
)
|
||||
VALUES
|
||||
(?, ?, ?, ?, ?);`,
|
||||
keyPair.KeycardUID, keyPair.KeycardName, keyPair.KeycardLocked, keyPair.KeyUID, keyPair.LastUpdateClock)
|
||||
keycard.KeycardUID, keycard.KeycardName, keycard.KeycardLocked, keycard.KeyUID, keycard.LastUpdateClock)
|
||||
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
|
||||
err = kp.addAccounts(tx, keyPair.KeycardUID, keyPair.AccountsAddresses)
|
||||
err = kp.addAccounts(tx, keycard.KeycardUID, keycard.AccountsAddresses)
|
||||
return err == nil, false, err
|
||||
}
|
||||
|
||||
err = kp.setLastUpdateClock(tx, keyPair.KeycardUID, keyPair.LastUpdateClock)
|
||||
err = kp.setLastUpdateClock(tx, keycard.KeycardUID, keycard.LastUpdateClock)
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
|
||||
err = kp.addAccounts(tx, keyPair.KeycardUID, keyPair.AccountsAddresses)
|
||||
err = kp.addAccounts(tx, keycard.KeycardUID, keycard.AccountsAddresses)
|
||||
return false, err == nil, err
|
||||
}
|
||||
|
||||
return false, false, err
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) SyncKeycards(syncingClock uint64, keypairsToSync []*KeyPair) (err error) {
|
||||
func (kp *Keycards) SyncKeycards(syncingClock uint64, keycardsToSync []*Keycard) (err error) {
|
||||
tx, err := kp.db.Begin()
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -358,23 +358,23 @@ func (kp *KeyPairs) SyncKeycards(syncingClock uint64, keypairsToSync []*KeyPair)
|
|||
}
|
||||
defer rows.Close()
|
||||
|
||||
var dbKeypairs []*KeyPair
|
||||
var dbKeycards []*Keycard
|
||||
for rows.Next() {
|
||||
keyPair := &KeyPair{}
|
||||
err := rows.Scan(&keyPair.KeycardUID, &keyPair.KeycardName, &keyPair.KeycardLocked, &keyPair.KeyUID,
|
||||
&keyPair.LastUpdateClock)
|
||||
keycard := &Keycard{}
|
||||
err := rows.Scan(&keycard.KeycardUID, &keycard.KeycardName, &keycard.KeycardLocked, &keycard.KeyUID,
|
||||
&keycard.LastUpdateClock)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dbKeypairs = append(dbKeypairs, keyPair)
|
||||
dbKeycards = append(dbKeycards, keycard)
|
||||
}
|
||||
|
||||
// apply those from `keypairsToSync` which are newer
|
||||
for _, syncKp := range keypairsToSync {
|
||||
// apply those from `keycardsToSync` which are newer
|
||||
for _, syncKp := range keycardsToSync {
|
||||
foundAtIndex := -1
|
||||
for i := range dbKeypairs {
|
||||
if dbKeypairs[i].KeycardUID == syncKp.KeycardUID {
|
||||
for i := range dbKeycards {
|
||||
if dbKeycards[i].KeycardUID == syncKp.KeycardUID {
|
||||
foundAtIndex = i
|
||||
break
|
||||
}
|
||||
|
@ -382,10 +382,10 @@ func (kp *KeyPairs) SyncKeycards(syncingClock uint64, keypairsToSync []*KeyPair)
|
|||
|
||||
doInsertOrReplace := true
|
||||
if foundAtIndex > -1 {
|
||||
if dbKeypairs[foundAtIndex].LastUpdateClock > syncKp.LastUpdateClock {
|
||||
if dbKeycards[foundAtIndex].LastUpdateClock > syncKp.LastUpdateClock {
|
||||
doInsertOrReplace = false
|
||||
}
|
||||
dbKeypairs = removeElementAtIndex(dbKeypairs, foundAtIndex)
|
||||
dbKeycards = removeElementAtIndex(dbKeycards, foundAtIndex)
|
||||
}
|
||||
|
||||
if doInsertOrReplace {
|
||||
|
@ -414,8 +414,8 @@ func (kp *KeyPairs) SyncKeycards(syncingClock uint64, keypairsToSync []*KeyPair)
|
|||
}
|
||||
}
|
||||
|
||||
// remove those from the db if they are not in `keypairsToSync` and if they are older than the moment `keypairsToSync` was created at
|
||||
for _, dbKp := range dbKeypairs {
|
||||
// remove those from the db if they are not in `keycardsToSync` and if they are older than the moment `keycardsToSync` was created at
|
||||
for _, dbKp := range dbKeycards {
|
||||
if dbKp.LastUpdateClock > syncingClock {
|
||||
continue
|
||||
}
|
||||
|
@ -429,7 +429,7 @@ func (kp *KeyPairs) SyncKeycards(syncingClock uint64, keypairsToSync []*KeyPair)
|
|||
return nil
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) RemoveMigratedAccountsForKeycard(kcUID string, accountAddresses []types.Address,
|
||||
func (kp *Keycards) RemoveMigratedAccountsForKeycard(kcUID string, accountAddresses []types.Address,
|
||||
clock uint64) (err error) {
|
||||
tx, proceed, err := kp.startTransactionAndCheckIfNeedToProceed(kcUID, clock)
|
||||
defer func() {
|
||||
|
@ -502,7 +502,7 @@ func (kp *KeyPairs) RemoveMigratedAccountsForKeycard(kcUID string, accountAddres
|
|||
return err
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) execUpdateQuery(kcUID string, clock uint64, field string, value interface{}) (err error) {
|
||||
func (kp *Keycards) execUpdateQuery(kcUID string, clock uint64, field string, value interface{}) (err error) {
|
||||
tx, proceed, err := kp.startTransactionAndCheckIfNeedToProceed(kcUID, clock)
|
||||
defer func() {
|
||||
if err == nil {
|
||||
|
@ -525,23 +525,23 @@ func (kp *KeyPairs) execUpdateQuery(kcUID string, clock uint64, field string, va
|
|||
return nil
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) KeycardLocked(kcUID string, clock uint64) (err error) {
|
||||
func (kp *Keycards) KeycardLocked(kcUID string, clock uint64) (err error) {
|
||||
return kp.execUpdateQuery(kcUID, clock, "keycard_locked", true)
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) KeycardUnlocked(kcUID string, clock uint64) (err error) {
|
||||
func (kp *Keycards) KeycardUnlocked(kcUID string, clock uint64) (err error) {
|
||||
return kp.execUpdateQuery(kcUID, clock, "keycard_locked", false)
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) UpdateKeycardUID(oldKcUID string, newKcUID string, clock uint64) (err error) {
|
||||
func (kp *Keycards) UpdateKeycardUID(oldKcUID string, newKcUID string, clock uint64) (err error) {
|
||||
return kp.execUpdateQuery(oldKcUID, clock, "keycard_uid", newKcUID)
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) SetKeycardName(kcUID string, kpName string, clock uint64) (err error) {
|
||||
func (kp *Keycards) SetKeycardName(kcUID string, kpName string, clock uint64) (err error) {
|
||||
return kp.execUpdateQuery(kcUID, clock, "keycard_name", kpName)
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) DeleteKeycard(kcUID string, clock uint64) (err error) {
|
||||
func (kp *Keycards) DeleteKeycard(kcUID string, clock uint64) (err error) {
|
||||
tx, proceed, err := kp.startTransactionAndCheckIfNeedToProceed(kcUID, clock)
|
||||
defer func() {
|
||||
if err == nil {
|
||||
|
@ -562,7 +562,7 @@ func (kp *KeyPairs) DeleteKeycard(kcUID string, clock uint64) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
func (kp *KeyPairs) DeleteKeypair(keyUID string) (err error) {
|
||||
func (kp *Keycards) DeleteAllKeycardsWithKeyUID(keyUID string) (err error) {
|
||||
delete, err := kp.db.Prepare(`
|
||||
DELETE
|
||||
FROM
|
|
@ -1,4 +1,4 @@
|
|||
package keypairs
|
||||
package keycards
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -9,26 +9,26 @@ import (
|
|||
"github.com/status-im/status-go/eth-node/types"
|
||||
)
|
||||
|
||||
func setupTestDB(t *testing.T) (*KeyPairs, func()) {
|
||||
func setupTestDB(t *testing.T) (*Keycards, func()) {
|
||||
db, stop, err := appdatabase.SetupTestSQLDB("settings-tests-")
|
||||
if err != nil {
|
||||
require.NoError(t, stop())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
d := NewKeyPairs(db)
|
||||
d := NewKeycards(db)
|
||||
|
||||
return d, func() {
|
||||
require.NoError(t, stop())
|
||||
}
|
||||
}
|
||||
|
||||
func TestKeypairs(t *testing.T) {
|
||||
func TestKeycards(t *testing.T) {
|
||||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
|
||||
keycardUID := "00000000000000000000000000000000"
|
||||
keyPair1 := KeyPair{
|
||||
keycard1 := Keycard{
|
||||
KeycardUID: "00000000000000000000000000000001",
|
||||
KeycardName: "Card01",
|
||||
KeycardLocked: false,
|
||||
|
@ -36,7 +36,7 @@ func TestKeypairs(t *testing.T) {
|
|||
KeyUID: "0000000000000000000000000000000000000000000000000000000000000001",
|
||||
LastUpdateClock: 100,
|
||||
}
|
||||
keyPair2 := KeyPair{
|
||||
keycard2 := Keycard{
|
||||
KeycardUID: "00000000000000000000000000000002",
|
||||
KeycardName: "Card02",
|
||||
KeycardLocked: false,
|
||||
|
@ -44,7 +44,7 @@ func TestKeypairs(t *testing.T) {
|
|||
KeyUID: "0000000000000000000000000000000000000000000000000000000000000002",
|
||||
LastUpdateClock: 200,
|
||||
}
|
||||
keyPair3 := KeyPair{
|
||||
keycard3 := Keycard{
|
||||
KeycardUID: "00000000000000000000000000000003",
|
||||
KeycardName: "Card02 Copy",
|
||||
KeycardLocked: false,
|
||||
|
@ -52,7 +52,7 @@ func TestKeypairs(t *testing.T) {
|
|||
KeyUID: "0000000000000000000000000000000000000000000000000000000000000002",
|
||||
LastUpdateClock: 300,
|
||||
}
|
||||
keyPair4 := KeyPair{
|
||||
keycard4 := Keycard{
|
||||
KeycardUID: "00000000000000000000000000000004",
|
||||
KeycardName: "Card04",
|
||||
KeycardLocked: false,
|
||||
|
@ -62,139 +62,139 @@ func TestKeypairs(t *testing.T) {
|
|||
}
|
||||
|
||||
// Test adding key pairs
|
||||
addedKc, addedAccs, err := db.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(keyPair1)
|
||||
addedKc, addedAccs, err := db.AddKeycardOrAddAccountsIfKeycardIsAdded(keycard1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, true, addedKc)
|
||||
require.Equal(t, false, addedAccs)
|
||||
addedKc, addedAccs, err = db.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(keyPair2)
|
||||
addedKc, addedAccs, err = db.AddKeycardOrAddAccountsIfKeycardIsAdded(keycard2)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, true, addedKc)
|
||||
require.Equal(t, false, addedAccs)
|
||||
addedKc, addedAccs, err = db.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(keyPair3)
|
||||
addedKc, addedAccs, err = db.AddKeycardOrAddAccountsIfKeycardIsAdded(keycard3)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, true, addedKc)
|
||||
require.Equal(t, false, addedAccs)
|
||||
// this should be added
|
||||
addedKc, addedAccs, err = db.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(KeyPair{
|
||||
KeycardUID: keyPair3.KeycardUID,
|
||||
addedKc, addedAccs, err = db.AddKeycardOrAddAccountsIfKeycardIsAdded(Keycard{
|
||||
KeycardUID: keycard3.KeycardUID,
|
||||
AccountsAddresses: []types.Address{{0x03}},
|
||||
LastUpdateClock: keyPair3.LastUpdateClock + 1,
|
||||
LastUpdateClock: keycard3.LastUpdateClock + 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, false, addedKc)
|
||||
require.Equal(t, true, addedAccs)
|
||||
// this should not be added as it has clock value less than last updated clock value
|
||||
addedKc, addedAccs, err = db.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(KeyPair{
|
||||
KeycardUID: keyPair3.KeycardUID,
|
||||
addedKc, addedAccs, err = db.AddKeycardOrAddAccountsIfKeycardIsAdded(Keycard{
|
||||
KeycardUID: keycard3.KeycardUID,
|
||||
AccountsAddresses: []types.Address{{0x04}},
|
||||
LastUpdateClock: keyPair3.LastUpdateClock,
|
||||
LastUpdateClock: keycard3.LastUpdateClock,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, false, addedKc)
|
||||
require.Equal(t, false, addedAccs)
|
||||
addedKc, addedAccs, err = db.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(keyPair4)
|
||||
addedKc, addedAccs, err = db.AddKeycardOrAddAccountsIfKeycardIsAdded(keycard4)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, true, addedKc)
|
||||
require.Equal(t, false, addedAccs)
|
||||
|
||||
// Test reading migrated key pairs
|
||||
rows, err := db.GetAllMigratedKeyPairs()
|
||||
rows, err := db.GetAllKnownKeycardsGroupedByKeyUID()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 3, len(rows))
|
||||
for _, kp := range rows {
|
||||
if kp.KeyUID == keyPair1.KeyUID {
|
||||
require.Equal(t, keyPair1.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keyPair1.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keyPair1.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keyPair1.AccountsAddresses), len(kp.AccountsAddresses))
|
||||
} else if kp.KeyUID == keyPair2.KeyUID { // keypair 2 and 3, cause 3 is a copy of 2
|
||||
require.Equal(t, keyPair2.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keyPair2.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keyPair2.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keyPair2.AccountsAddresses)+1, len(kp.AccountsAddresses)) // Add 1, cause one account is additionally added for the same keypair.
|
||||
if kp.KeyUID == keycard1.KeyUID {
|
||||
require.Equal(t, keycard1.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keycard1.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keycard1.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keycard1.AccountsAddresses), len(kp.AccountsAddresses))
|
||||
} else if kp.KeyUID == keycard2.KeyUID { // keycard 2 and 3, cause 3 is a copy of 2
|
||||
require.Equal(t, keycard2.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keycard2.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keycard2.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keycard2.AccountsAddresses)+1, len(kp.AccountsAddresses)) // Add 1, cause one account is additionally added for the same keycard.
|
||||
} else {
|
||||
require.Equal(t, keyPair4.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keyPair4.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keyPair4.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keyPair4.AccountsAddresses), len(kp.AccountsAddresses))
|
||||
require.Equal(t, keycard4.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keycard4.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keycard4.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keycard4.AccountsAddresses), len(kp.AccountsAddresses))
|
||||
}
|
||||
}
|
||||
|
||||
rows, err = db.GetMigratedKeyPairByKeyUID(keyPair1.KeyUID)
|
||||
rows, err = db.GetKeycardByKeyUID(keycard1.KeyUID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(rows))
|
||||
require.Equal(t, keyPair1.KeyUID, rows[0].KeyUID)
|
||||
require.Equal(t, keyPair1.KeycardUID, rows[0].KeycardUID)
|
||||
require.Equal(t, keyPair1.KeycardName, rows[0].KeycardName)
|
||||
require.Equal(t, keyPair1.KeycardLocked, rows[0].KeycardLocked)
|
||||
require.Equal(t, len(keyPair1.AccountsAddresses), len(rows[0].AccountsAddresses))
|
||||
require.Equal(t, keyPair1.LastUpdateClock, rows[0].LastUpdateClock)
|
||||
require.Equal(t, keycard1.KeyUID, rows[0].KeyUID)
|
||||
require.Equal(t, keycard1.KeycardUID, rows[0].KeycardUID)
|
||||
require.Equal(t, keycard1.KeycardName, rows[0].KeycardName)
|
||||
require.Equal(t, keycard1.KeycardLocked, rows[0].KeycardLocked)
|
||||
require.Equal(t, len(keycard1.AccountsAddresses), len(rows[0].AccountsAddresses))
|
||||
require.Equal(t, keycard1.LastUpdateClock, rows[0].LastUpdateClock)
|
||||
|
||||
rows, err = db.GetAllKnownKeycards()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 4, len(rows))
|
||||
for _, kp := range rows {
|
||||
if kp.KeycardUID == keyPair1.KeycardUID {
|
||||
require.Equal(t, keyPair1.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keyPair1.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keyPair1.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keyPair1.AccountsAddresses), len(kp.AccountsAddresses))
|
||||
require.Equal(t, keyPair1.LastUpdateClock, kp.LastUpdateClock)
|
||||
} else if kp.KeycardUID == keyPair2.KeycardUID {
|
||||
require.Equal(t, keyPair2.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keyPair2.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keyPair2.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keyPair2.AccountsAddresses), len(kp.AccountsAddresses))
|
||||
require.Equal(t, keyPair2.LastUpdateClock, kp.LastUpdateClock)
|
||||
} else if kp.KeycardUID == keyPair3.KeycardUID {
|
||||
require.Equal(t, keyPair3.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keyPair3.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keyPair3.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keyPair3.AccountsAddresses)+1, len(kp.AccountsAddresses)) // Add 1, cause one account is additionally added.
|
||||
require.Equal(t, keyPair3.LastUpdateClock+1, kp.LastUpdateClock)
|
||||
if kp.KeycardUID == keycard1.KeycardUID {
|
||||
require.Equal(t, keycard1.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keycard1.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keycard1.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keycard1.AccountsAddresses), len(kp.AccountsAddresses))
|
||||
require.Equal(t, keycard1.LastUpdateClock, kp.LastUpdateClock)
|
||||
} else if kp.KeycardUID == keycard2.KeycardUID {
|
||||
require.Equal(t, keycard2.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keycard2.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keycard2.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keycard2.AccountsAddresses), len(kp.AccountsAddresses))
|
||||
require.Equal(t, keycard2.LastUpdateClock, kp.LastUpdateClock)
|
||||
} else if kp.KeycardUID == keycard3.KeycardUID {
|
||||
require.Equal(t, keycard3.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keycard3.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keycard3.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keycard3.AccountsAddresses)+1, len(kp.AccountsAddresses)) // Add 1, cause one account is additionally added.
|
||||
require.Equal(t, keycard3.LastUpdateClock+1, kp.LastUpdateClock)
|
||||
} else {
|
||||
require.Equal(t, keyPair4.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keyPair4.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keyPair4.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keyPair4.AccountsAddresses), len(kp.AccountsAddresses))
|
||||
require.Equal(t, keyPair4.LastUpdateClock, kp.LastUpdateClock)
|
||||
require.Equal(t, keycard4.KeycardUID, kp.KeycardUID)
|
||||
require.Equal(t, keycard4.KeycardName, kp.KeycardName)
|
||||
require.Equal(t, keycard4.KeycardLocked, kp.KeycardLocked)
|
||||
require.Equal(t, len(keycard4.AccountsAddresses), len(kp.AccountsAddresses))
|
||||
require.Equal(t, keycard4.LastUpdateClock, kp.LastUpdateClock)
|
||||
}
|
||||
}
|
||||
|
||||
// Test seting a new keycard name
|
||||
err = db.SetKeycardName(keyPair1.KeycardUID, "Card101", 1000)
|
||||
err = db.SetKeycardName(keycard1.KeycardUID, "Card101", 1000)
|
||||
require.NoError(t, err)
|
||||
rows, err = db.GetAllMigratedKeyPairs()
|
||||
rows, err = db.GetAllKnownKeycardsGroupedByKeyUID()
|
||||
require.NoError(t, err)
|
||||
newKeycardName := ""
|
||||
for _, kp := range rows {
|
||||
if kp.KeyUID == keyPair1.KeyUID {
|
||||
if kp.KeyUID == keycard1.KeyUID {
|
||||
newKeycardName = kp.KeycardName
|
||||
}
|
||||
}
|
||||
require.Equal(t, "Card101", newKeycardName)
|
||||
|
||||
// Test seting a new keycard name with an old clock value
|
||||
err = db.SetKeycardName(keyPair1.KeycardUID, "Card102", 999) // clock is less than the last one
|
||||
err = db.SetKeycardName(keycard1.KeycardUID, "Card102", 999) // clock is less than the last one
|
||||
require.NoError(t, err)
|
||||
rows, err = db.GetAllMigratedKeyPairs()
|
||||
rows, err = db.GetAllKnownKeycardsGroupedByKeyUID()
|
||||
require.NoError(t, err)
|
||||
newKeycardName = ""
|
||||
for _, kp := range rows {
|
||||
if kp.KeyUID == keyPair1.KeyUID {
|
||||
if kp.KeyUID == keycard1.KeyUID {
|
||||
newKeycardName = kp.KeycardName
|
||||
}
|
||||
}
|
||||
require.Equal(t, "Card101", newKeycardName)
|
||||
|
||||
// Test locking a keycard
|
||||
err = db.KeycardLocked(keyPair1.KeycardUID, 1001)
|
||||
err = db.KeycardLocked(keycard1.KeycardUID, 1001)
|
||||
require.NoError(t, err)
|
||||
rows, err = db.GetAllMigratedKeyPairs()
|
||||
rows, err = db.GetAllKnownKeycardsGroupedByKeyUID()
|
||||
require.NoError(t, err)
|
||||
locked := false
|
||||
for _, kp := range rows {
|
||||
if kp.KeyUID == keyPair1.KeyUID {
|
||||
if kp.KeyUID == keycard1.KeyUID {
|
||||
locked = kp.KeycardLocked
|
||||
}
|
||||
}
|
||||
|
@ -202,39 +202,39 @@ func TestKeypairs(t *testing.T) {
|
|||
|
||||
// Test detleting accounts (addresses) for a certain keycard
|
||||
const numOfAccountsToRemove = 2
|
||||
require.Greater(t, len(keyPair1.AccountsAddresses), numOfAccountsToRemove)
|
||||
accountsToRemove := keyPair1.AccountsAddresses[:numOfAccountsToRemove]
|
||||
err = db.RemoveMigratedAccountsForKeycard(keyPair1.KeycardUID, accountsToRemove, 1002)
|
||||
require.Greater(t, len(keycard1.AccountsAddresses), numOfAccountsToRemove)
|
||||
accountsToRemove := keycard1.AccountsAddresses[:numOfAccountsToRemove]
|
||||
err = db.RemoveMigratedAccountsForKeycard(keycard1.KeycardUID, accountsToRemove, 1002)
|
||||
require.NoError(t, err)
|
||||
rows, err = db.GetMigratedKeyPairByKeyUID(keyPair1.KeyUID)
|
||||
rows, err = db.GetKeycardByKeyUID(keycard1.KeyUID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(rows))
|
||||
require.Equal(t, len(keyPair1.AccountsAddresses)-numOfAccountsToRemove, len(rows[0].AccountsAddresses))
|
||||
require.Equal(t, len(keycard1.AccountsAddresses)-numOfAccountsToRemove, len(rows[0].AccountsAddresses))
|
||||
|
||||
// Test deleting accounts one by one, with the last deleted account keycard should be delete as well
|
||||
for i, addr := range keyPair4.AccountsAddresses {
|
||||
err = db.RemoveMigratedAccountsForKeycard(keyPair4.KeycardUID, []types.Address{addr}, 1003+uint64(i))
|
||||
for i, addr := range keycard4.AccountsAddresses {
|
||||
err = db.RemoveMigratedAccountsForKeycard(keycard4.KeycardUID, []types.Address{addr}, 1003+uint64(i))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
rows, err = db.GetAllMigratedKeyPairs()
|
||||
rows, err = db.GetAllKnownKeycardsGroupedByKeyUID()
|
||||
require.NoError(t, err)
|
||||
// Test if correct keycard is deleted
|
||||
deletedKeyPair4 := true
|
||||
deletedKeycard4 := true
|
||||
for _, kp := range rows {
|
||||
if kp.KeycardUID == keyPair4.KeycardUID {
|
||||
deletedKeyPair4 = false
|
||||
if kp.KeycardUID == keycard4.KeycardUID {
|
||||
deletedKeycard4 = false
|
||||
}
|
||||
}
|
||||
require.Equal(t, true, deletedKeyPair4)
|
||||
require.Equal(t, true, deletedKeycard4)
|
||||
|
||||
// Test update keycard uid
|
||||
err = db.UpdateKeycardUID(keyPair1.KeycardUID, keycardUID, 1100)
|
||||
err = db.UpdateKeycardUID(keycard1.KeycardUID, keycardUID, 1100)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test unlocking a locked keycard
|
||||
err = db.KeycardUnlocked(keycardUID, 1101)
|
||||
require.NoError(t, err)
|
||||
rows, err = db.GetAllMigratedKeyPairs()
|
||||
rows, err = db.GetAllKnownKeycardsGroupedByKeyUID()
|
||||
require.NoError(t, err)
|
||||
locked = true
|
||||
for _, kp := range rows {
|
||||
|
@ -247,7 +247,7 @@ func TestKeypairs(t *testing.T) {
|
|||
// Test detleting a keycard
|
||||
err = db.DeleteKeycard(keycardUID, 1102)
|
||||
require.NoError(t, err)
|
||||
rows, err = db.GetAllMigratedKeyPairs()
|
||||
rows, err = db.GetAllKnownKeycardsGroupedByKeyUID()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(rows))
|
||||
// Test if correct keycard is deleted
|
||||
|
@ -259,17 +259,17 @@ func TestKeypairs(t *testing.T) {
|
|||
}
|
||||
require.Equal(t, true, deletedKeyCard)
|
||||
|
||||
// Test detleting a keypair
|
||||
err = db.DeleteKeypair(keyPair2.KeyUID)
|
||||
// Test detleting a keycard
|
||||
err = db.DeleteAllKeycardsWithKeyUID(keycard2.KeyUID)
|
||||
require.NoError(t, err)
|
||||
rows, err = db.GetAllMigratedKeyPairs()
|
||||
rows, err = db.GetAllKnownKeycardsGroupedByKeyUID()
|
||||
require.NoError(t, err)
|
||||
// Test if correct keycard is deleted
|
||||
deletedKeyPair2And3 := true
|
||||
deletedKeycard2And3 := true
|
||||
for _, kp := range rows {
|
||||
if kp.KeyUID == keyPair2.KeyUID {
|
||||
deletedKeyPair2And3 = false
|
||||
if kp.KeyUID == keycard2.KeyUID {
|
||||
deletedKeycard2And3 = false
|
||||
}
|
||||
}
|
||||
require.Equal(t, true, deletedKeyPair2And3)
|
||||
require.Equal(t, true, deletedKeycard2And3)
|
||||
}
|
|
@ -732,7 +732,7 @@ func (s *MessengerBackupSuite) TestBackupKeycards() {
|
|||
bob1 := s.m
|
||||
allKeycardsToSync := getKeycardsForTest()
|
||||
for _, kp := range allKeycardsToSync {
|
||||
addedKc, addedAccs, err := bob1.settings.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
addedKc, addedAccs, err := bob1.settings.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/golang/protobuf/proto"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/multiaccounts/keypairs"
|
||||
"github.com/status-im/status-go/multiaccounts/keycards"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
)
|
||||
|
@ -69,15 +69,15 @@ func (m *Messenger) syncAllKeycards(ctx context.Context, rawMessageHandler RawMe
|
|||
return m.saveChat(chat)
|
||||
}
|
||||
|
||||
func (m *Messenger) syncReceivedKeycards(syncMessage protobuf.SyncAllKeycards) ([]*keypairs.KeyPair, error) {
|
||||
var keypairsToSync []*keypairs.KeyPair
|
||||
func (m *Messenger) syncReceivedKeycards(syncMessage protobuf.SyncAllKeycards) ([]*keycards.Keycard, error) {
|
||||
var keycardsToSync []*keycards.Keycard
|
||||
for _, syncKc := range syncMessage.Keycards {
|
||||
var kp = &keypairs.KeyPair{}
|
||||
var kp = &keycards.Keycard{}
|
||||
kp.FromSyncKeycard(syncKc)
|
||||
keypairsToSync = append(keypairsToSync, kp)
|
||||
keycardsToSync = append(keycardsToSync, kp)
|
||||
}
|
||||
|
||||
err := m.settings.SyncKeycards(syncMessage.Clock, keypairsToSync)
|
||||
err := m.settings.SyncKeycards(syncMessage.Clock, keycardsToSync)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -131,17 +131,17 @@ func (m *Messenger) dispatchKeycardActivity(ctx context.Context, syncMessage pro
|
|||
|
||||
func (m *Messenger) handleSyncKeycardActivity(state *ReceivedMessageState, syncMessage protobuf.SyncKeycardAction) (err error) {
|
||||
|
||||
var kcAction = &keypairs.KeycardAction{
|
||||
var kcAction = &keycards.KeycardAction{
|
||||
Action: protobuf.SyncKeycardAction_Action_name[int32(syncMessage.Action)],
|
||||
OldKeycardUID: syncMessage.OldKeycardUid,
|
||||
Keycard: &keypairs.KeyPair{},
|
||||
Keycard: &keycards.Keycard{},
|
||||
}
|
||||
kcAction.Keycard.FromSyncKeycard(syncMessage.Keycard)
|
||||
|
||||
switch syncMessage.Action {
|
||||
case protobuf.SyncKeycardAction_KEYCARD_ADDED,
|
||||
protobuf.SyncKeycardAction_ACCOUNTS_ADDED:
|
||||
_, _, err = m.settings.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kcAction.Keycard)
|
||||
_, _, err = m.settings.AddKeycardOrAddAccountsIfKeycardIsAdded(*kcAction.Keycard)
|
||||
case protobuf.SyncKeycardAction_KEYCARD_DELETED:
|
||||
err = m.settings.DeleteKeycard(kcAction.Keycard.KeycardUID, kcAction.Keycard.LastUpdateClock)
|
||||
case protobuf.SyncKeycardAction_ACCOUNTS_REMOVED:
|
||||
|
@ -170,8 +170,8 @@ func (m *Messenger) handleSyncKeycardActivity(state *ReceivedMessageState, syncM
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *Messenger) AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(ctx context.Context, kp *keypairs.KeyPair) (added bool, err error) {
|
||||
addedKc, addedAccs, err := m.settings.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
func (m *Messenger) AddKeycardOrAddAccountsIfKeycardIsAdded(ctx context.Context, kp *keycards.Keycard) (added bool, err error) {
|
||||
addedKc, addedAccs, err := m.settings.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
if err != nil {
|
||||
return addedKc || addedAccs, err
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/status-im/status-go/appmetrics"
|
||||
"github.com/status-im/status-go/images"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/multiaccounts/keypairs"
|
||||
"github.com/status-im/status-go/multiaccounts/keycards"
|
||||
"github.com/status-im/status-go/multiaccounts/settings"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
"github.com/status-im/status-go/protocol/communities"
|
||||
|
@ -75,8 +75,8 @@ type MessengerResponse struct {
|
|||
trustStatus map[string]verification.TrustStatus
|
||||
emojiReactions map[string]*EmojiReaction
|
||||
savedAddresses map[string]*wallet.SavedAddress
|
||||
keycards []*keypairs.KeyPair
|
||||
keycardActions []*keypairs.KeycardAction
|
||||
keycards []*keycards.Keycard
|
||||
keycardActions []*keycards.KeycardAction
|
||||
socialLinkSettings []*identity.SocialLink
|
||||
ensUsernameDetails []*ensservice.UsernameDetail
|
||||
}
|
||||
|
@ -117,8 +117,8 @@ func (r *MessengerResponse) MarshalJSON() ([]byte, error) {
|
|||
DiscordMessages []*protobuf.DiscordMessage `json:"discordMessages,omitempty"`
|
||||
DiscordMessageAttachments []*protobuf.DiscordMessageAttachment `json:"discordMessageAtachments,omitempty"`
|
||||
SavedAddresses []*wallet.SavedAddress `json:"savedAddresses,omitempty"`
|
||||
Keycards []*keypairs.KeyPair `json:"keycards,omitempty"`
|
||||
KeycardActions []*keypairs.KeycardAction `json:"keycardActions,omitempty"`
|
||||
Keycards []*keycards.Keycard `json:"keycards,omitempty"`
|
||||
KeycardActions []*keycards.KeycardAction `json:"keycardActions,omitempty"`
|
||||
SocialLinkSettings []*identity.SocialLink `json:"socialLinkSettings,omitempty"`
|
||||
EnsUsernameDetails []*ensservice.UsernameDetail `json:"ensUsernameDetails,omitempty"`
|
||||
}{
|
||||
|
@ -460,23 +460,23 @@ func (r *MessengerResponse) SavedAddresses() []*wallet.SavedAddress {
|
|||
return ers
|
||||
}
|
||||
|
||||
func (r *MessengerResponse) AddAllKnownKeycards(keycards []*keypairs.KeyPair) {
|
||||
func (r *MessengerResponse) AddAllKnownKeycards(keycards []*keycards.Keycard) {
|
||||
r.keycards = append(r.keycards, keycards...)
|
||||
}
|
||||
|
||||
func (r *MessengerResponse) AllKnownKeycards() []*keypairs.KeyPair {
|
||||
func (r *MessengerResponse) AllKnownKeycards() []*keycards.Keycard {
|
||||
return r.keycards
|
||||
}
|
||||
|
||||
func (r *MessengerResponse) AddKeycardAction(keycardAction *keypairs.KeycardAction) {
|
||||
func (r *MessengerResponse) AddKeycardAction(keycardAction *keycards.KeycardAction) {
|
||||
r.keycardActions = append(r.keycardActions, keycardAction)
|
||||
}
|
||||
|
||||
func (r *MessengerResponse) AddKeycardActions(keycardActions []*keypairs.KeycardAction) {
|
||||
func (r *MessengerResponse) AddKeycardActions(keycardActions []*keycards.KeycardAction) {
|
||||
r.keycardActions = append(r.keycardActions, keycardActions...)
|
||||
}
|
||||
|
||||
func (r *MessengerResponse) KeycardActions() []*keypairs.KeycardAction {
|
||||
func (r *MessengerResponse) KeycardActions() []*keycards.KeycardAction {
|
||||
return r.keycardActions
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ func (s *MessengerSyncKeycardChangeSuite) TestAddingNewKeycards() {
|
|||
// Add key cards on sender
|
||||
allKeycardsToSync := getKeycardsForTest()[:2]
|
||||
for _, kp := range allKeycardsToSync {
|
||||
added, err := s.main.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(context.Background(), kp)
|
||||
added, err := s.main.AddKeycardOrAddAccountsIfKeycardIsAdded(context.Background(), kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, added)
|
||||
}
|
||||
|
@ -123,13 +123,13 @@ func (s *MessengerSyncKeycardChangeSuite) TestAddingAccountsToKeycard() {
|
|||
|
||||
// Add keycard on sender
|
||||
keycardToSync := getKeycardsForTest()[:1][0]
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
||||
// Add the same keycard on receiver
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -138,7 +138,7 @@ func (s *MessengerSyncKeycardChangeSuite) TestAddingAccountsToKeycard() {
|
|||
updatedKeycard := getKeycardsForTest()[:1][0]
|
||||
updatedKeycard.AccountsAddresses = []types.Address{{0x011}, {0x022}, {0x033}, {0x044}}
|
||||
|
||||
added, err := s.main.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(context.Background(), updatedKeycard)
|
||||
added, err := s.main.AddKeycardOrAddAccountsIfKeycardIsAdded(context.Background(), updatedKeycard)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, added)
|
||||
|
||||
|
@ -167,13 +167,13 @@ func (s *MessengerSyncKeycardChangeSuite) TestRemovingAccountsFromKeycard() {
|
|||
|
||||
// Add keycard on sender
|
||||
keycardToSync := getKeycardsForTest()[:1][0]
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
||||
// Add the same keycard on receiver
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -208,13 +208,13 @@ func (s *MessengerSyncKeycardChangeSuite) TestRemovingAllAccountsFromKeycard() {
|
|||
|
||||
// Add keycard on sender
|
||||
keycardToSync := getKeycardsForTest()[:1][0]
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
||||
// Add the same keycard on receiver
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -245,13 +245,13 @@ func (s *MessengerSyncKeycardChangeSuite) TestDeleteKeycard() {
|
|||
|
||||
// Add keycard on sender
|
||||
keycardToSync := getKeycardsForTest()[:1][0]
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
||||
// Add the same keycard on receiver
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -281,13 +281,13 @@ func (s *MessengerSyncKeycardChangeSuite) TestSettingKeycardName() {
|
|||
|
||||
// Add keycard on sender
|
||||
keycardToSync := getKeycardsForTest()[:1][0]
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
||||
// Add the same keycard on receiver
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -323,13 +323,13 @@ func (s *MessengerSyncKeycardChangeSuite) TestSettingKeycardNameWithOlderClock()
|
|||
|
||||
// Add keycard on sender
|
||||
keycardToSync := getKeycardsForTest()[:1][0]
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
||||
// Add the same keycard on receiver
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -365,13 +365,13 @@ func (s *MessengerSyncKeycardChangeSuite) TestSettingKeycardLocked() {
|
|||
|
||||
// Add keycard on sender
|
||||
keycardToSync := getKeycardsForTest()[:1][0]
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
||||
// Add the same keycard on receiver
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -406,13 +406,13 @@ func (s *MessengerSyncKeycardChangeSuite) TestSettingKeycardLockedOlderClock() {
|
|||
|
||||
// Add keycard on sender
|
||||
keycardToSync := getKeycardsForTest()[:1][0]
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
||||
// Add the same keycard on receiver
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -448,13 +448,13 @@ func (s *MessengerSyncKeycardChangeSuite) TestSettingKeycardUnlocked() {
|
|||
// Add keycard on sender
|
||||
keycardToSync := getKeycardsForTest()[:1][0]
|
||||
keycardToSync.KeycardLocked = true
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
||||
// Add the same keycard on receiver
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -490,13 +490,13 @@ func (s *MessengerSyncKeycardChangeSuite) TestSettingKeycardUnlockedOlderClock()
|
|||
// Add keycard on sender
|
||||
keycardToSync := getKeycardsForTest()[:1][0]
|
||||
keycardToSync.KeycardLocked = true
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
||||
// Add the same keycard on receiver
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -531,13 +531,13 @@ func (s *MessengerSyncKeycardChangeSuite) TestUpdatingKeycardUid() {
|
|||
|
||||
// Add keycard on sender
|
||||
keycardToSync := getKeycardsForTest()[:1][0]
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
||||
// Add the same keycard on receiver
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -573,13 +573,13 @@ func (s *MessengerSyncKeycardChangeSuite) TestUpdatingKeycardUidOldClock() {
|
|||
|
||||
// Add keycard on sender
|
||||
keycardToSync := getKeycardsForTest()[:1][0]
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
||||
// Add the same keycard on receiver
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*keycardToSync)
|
||||
addedKc, addedAccs, err = dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*keycardToSync)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/multiaccounts/keypairs"
|
||||
"github.com/status-im/status-go/multiaccounts/keycards"
|
||||
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
||||
"github.com/status-im/status-go/protocol/tt"
|
||||
"github.com/status-im/status-go/waku"
|
||||
|
@ -91,7 +91,7 @@ func (s *MessengerSyncKeycardsStateSuite) newMessenger(shh types.Waku) *Messenge
|
|||
return messenger
|
||||
}
|
||||
|
||||
func sameKeycards(a, b *keypairs.KeyPair) bool {
|
||||
func sameKeycards(a, b *keycards.Keycard) bool {
|
||||
same := a.KeycardUID == b.KeycardUID &&
|
||||
a.KeyUID == b.KeyUID &&
|
||||
a.KeycardName == b.KeycardName &&
|
||||
|
@ -118,8 +118,8 @@ func sameKeycards(a, b *keypairs.KeyPair) bool {
|
|||
return same
|
||||
}
|
||||
|
||||
func getKeycardsForTest() []*keypairs.KeyPair {
|
||||
keyPair1 := keypairs.KeyPair{
|
||||
func getKeycardsForTest() []*keycards.Keycard {
|
||||
keycard1 := keycards.Keycard{
|
||||
KeycardUID: "00000000000000000000000000000001",
|
||||
KeycardName: "Card01",
|
||||
KeycardLocked: false,
|
||||
|
@ -127,7 +127,7 @@ func getKeycardsForTest() []*keypairs.KeyPair {
|
|||
KeyUID: "0000000000000000000000000000000000000000000000000000000000000001",
|
||||
LastUpdateClock: 100,
|
||||
}
|
||||
keyPair2 := keypairs.KeyPair{
|
||||
keycard2 := keycards.Keycard{
|
||||
KeycardUID: "00000000000000000000000000000002",
|
||||
KeycardName: "Card02",
|
||||
KeycardLocked: false,
|
||||
|
@ -135,7 +135,7 @@ func getKeycardsForTest() []*keypairs.KeyPair {
|
|||
KeyUID: "0000000000000000000000000000000000000000000000000000000000000002",
|
||||
LastUpdateClock: 200,
|
||||
}
|
||||
keyPair3 := keypairs.KeyPair{
|
||||
keycard3 := keycards.Keycard{
|
||||
KeycardUID: "00000000000000000000000000000003",
|
||||
KeycardName: "Card02 Copy",
|
||||
KeycardLocked: false,
|
||||
|
@ -143,7 +143,7 @@ func getKeycardsForTest() []*keypairs.KeyPair {
|
|||
KeyUID: "0000000000000000000000000000000000000000000000000000000000000002",
|
||||
LastUpdateClock: 300,
|
||||
}
|
||||
keyPair4 := keypairs.KeyPair{
|
||||
keycard4 := keycards.Keycard{
|
||||
KeycardUID: "00000000000000000000000000000004",
|
||||
KeycardName: "Card04",
|
||||
KeycardLocked: false,
|
||||
|
@ -152,7 +152,7 @@ func getKeycardsForTest() []*keypairs.KeyPair {
|
|||
LastUpdateClock: 400,
|
||||
}
|
||||
|
||||
return []*keypairs.KeyPair{&keyPair1, &keyPair2, &keyPair3, &keyPair4}
|
||||
return []*keycards.Keycard{&keycard1, &keycard2, &keycard3, &keycard4}
|
||||
}
|
||||
|
||||
func (s *MessengerSyncKeycardsStateSuite) TestSyncKeycardsIfReceiverHasNoKeycards() {
|
||||
|
@ -162,7 +162,7 @@ func (s *MessengerSyncKeycardsStateSuite) TestSyncKeycardsIfReceiverHasNoKeycard
|
|||
// Add keycards on sender
|
||||
allKeycardsToSync := getKeycardsForTest()
|
||||
for _, kp := range allKeycardsToSync {
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -195,7 +195,7 @@ func (s *MessengerSyncKeycardsStateSuite) TestSyncKeycardsIfReceiverHasKeycardsO
|
|||
// Add keycards on sender
|
||||
allKeycardsToSync := getKeycardsForTest()
|
||||
for _, kp := range allKeycardsToSync {
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -210,7 +210,7 @@ func (s *MessengerSyncKeycardsStateSuite) TestSyncKeycardsIfReceiverHasKeycardsO
|
|||
keycardsOnReceiver[1].LastUpdateClock = keycardsOnReceiver[1].LastUpdateClock - 1
|
||||
|
||||
for _, kp := range keycardsOnReceiver {
|
||||
addedKc, addedAccs, err := dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
addedKc, addedAccs, err := dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -243,7 +243,7 @@ func (s *MessengerSyncKeycardsStateSuite) TestSyncKeycardsIfKeycardsWereDeletedO
|
|||
// Add keycards on sender
|
||||
allKeycardsToSync := getKeycardsForTest()[:2]
|
||||
for _, kp := range allKeycardsToSync {
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -252,7 +252,7 @@ func (s *MessengerSyncKeycardsStateSuite) TestSyncKeycardsIfKeycardsWereDeletedO
|
|||
// Add keycards on receiver
|
||||
keycardsOnReceiver := getKeycardsForTest()
|
||||
for _, kp := range keycardsOnReceiver {
|
||||
addedKc, addedAccs, err := dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
addedKc, addedAccs, err := dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -285,7 +285,7 @@ func (s *MessengerSyncKeycardsStateSuite) TestSyncKeycardsIfReceiverHasNewerKeyc
|
|||
// Add keycards on sender
|
||||
allKeycardsToSync := getKeycardsForTest()[:2]
|
||||
for _, kp := range allKeycardsToSync {
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -299,7 +299,7 @@ func (s *MessengerSyncKeycardsStateSuite) TestSyncKeycardsIfReceiverHasNewerKeyc
|
|||
keycardsOnReceiver[3].KeycardName = "NewerCardName-3"
|
||||
keycardsOnReceiver[3].LastUpdateClock = clock + 1000
|
||||
for _, kp := range keycardsOnReceiver {
|
||||
addedKc, addedAccs, err := dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
addedKc, addedAccs, err := dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -337,7 +337,7 @@ func (s *MessengerSyncKeycardsStateSuite) TestSyncKeycardsIfReceiverAndSenderHas
|
|||
// Add keycards on sender
|
||||
allKeycardsToSync := getKeycardsForTest()[:2]
|
||||
for _, kp := range allKeycardsToSync {
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -352,7 +352,7 @@ func (s *MessengerSyncKeycardsStateSuite) TestSyncKeycardsIfReceiverAndSenderHas
|
|||
keycardsOnReceiver[1].LastUpdateClock = clock + 1000
|
||||
|
||||
for _, kp := range keycardsOnReceiver {
|
||||
addedKc, addedAccs, err := dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
addedKc, addedAccs, err := dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -390,7 +390,7 @@ func (s *MessengerSyncKeycardsStateSuite) TestSyncKeycardsIfReceiverHasNewerKeyc
|
|||
// Add keycards on sender
|
||||
allKeycardsToSync := getKeycardsForTest()
|
||||
for _, kp := range allKeycardsToSync {
|
||||
addedKc, addedAccs, err := senderDb.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
addedKc, addedAccs, err := senderDb.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
@ -405,7 +405,7 @@ func (s *MessengerSyncKeycardsStateSuite) TestSyncKeycardsIfReceiverHasNewerKeyc
|
|||
keycardsOnReceiver[1].LastUpdateClock = clock + 1000
|
||||
|
||||
for _, kp := range keycardsOnReceiver {
|
||||
addedKc, addedAccs, err := dbOnReceiver.AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(*kp)
|
||||
addedKc, addedAccs, err := dbOnReceiver.AddKeycardOrAddAccountsIfKeycardIsAdded(*kp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(true, addedKc)
|
||||
s.Require().Equal(false, addedAccs)
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/multiaccounts/keypairs"
|
||||
"github.com/status-im/status-go/multiaccounts/keycards"
|
||||
"github.com/status-im/status-go/multiaccounts/settings"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
)
|
||||
|
@ -13,7 +13,7 @@ type WakuBackedUpDataResponse struct {
|
|||
FetchingDataProgress map[string]protobuf.FetchingBackedUpDataDetails // key represents the data/section backup details refer to
|
||||
Profile *BackedUpProfile
|
||||
Setting *settings.SyncSettingField
|
||||
Keycards []*keypairs.KeyPair
|
||||
Keycards []*keycards.Keycard
|
||||
WalletAccount *accounts.Account
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ func (sfwr *WakuBackedUpDataResponse) MarshalJSON() ([]byte, error) {
|
|||
FetchingDataProgress map[string]FetchingBackupedDataDetails `json:"fetchingBackedUpDataProgress,omitempty"`
|
||||
Profile *BackedUpProfile `json:"backedUpProfile,omitempty"`
|
||||
Setting *settings.SyncSettingField `json:"backedUpSettings,omitempty"`
|
||||
Keycards []*keypairs.KeyPair `json:"backedUpKeycards,omitempty"`
|
||||
Keycards []*keycards.Keycard `json:"backedUpKeycards,omitempty"`
|
||||
WalletAccount *accounts.Account `json:"backedUpWalletAccount,omitempty"`
|
||||
}{
|
||||
Profile: sfwr.Profile,
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/status-im/status-go/account"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/multiaccounts/keypairs"
|
||||
"github.com/status-im/status-go/multiaccounts/keycards"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/protocol"
|
||||
)
|
||||
|
@ -93,12 +93,12 @@ func (api *API) DeleteAccount(ctx context.Context, address types.Address) error
|
|||
lastAcccountOfKeypairWithTheSameKey := len(allAccountsOfKeypairWithKeyUID) == 1
|
||||
|
||||
if acc.Type != accounts.AccountTypeWatch {
|
||||
migratedKeyPairs, err := api.db.GetMigratedKeyPairByKeyUID(acc.KeyUID)
|
||||
knownKeycardsForKeyUID, err := api.db.GetKeycardByKeyUID(acc.KeyUID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(migratedKeyPairs) == 0 {
|
||||
if len(knownKeycardsForKeyUID) == 0 {
|
||||
err = api.manager.DeleteAccount(address)
|
||||
var e *account.ErrCannotLocateKeyFile
|
||||
if err != nil && !errors.As(err, &e) {
|
||||
|
@ -269,7 +269,7 @@ func (api *API) VerifyPassword(password string) bool {
|
|||
return api.VerifyKeystoreFileForAccount(address, password)
|
||||
}
|
||||
|
||||
func (api *API) AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(ctx context.Context, kcUID string, kpName string, keyUID string, accountAddresses []string) error {
|
||||
func (api *API) AddKeycardOrAddAccountsIfKeycardIsAdded(ctx context.Context, kcUID string, kpName string, keyUID string, accountAddresses []string) error {
|
||||
if len(accountAddresses) == 0 {
|
||||
return errors.New("cannot migrate a keypair without any address")
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ func (api *API) AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(ctx context.Cont
|
|||
return errors.New("an account being migrated doesn't contain `derived_from` field set")
|
||||
}
|
||||
|
||||
kp := keypairs.KeyPair{
|
||||
kp := keycards.Keycard{
|
||||
KeycardUID: kcUID,
|
||||
KeycardName: kpName,
|
||||
KeycardLocked: false,
|
||||
|
@ -294,19 +294,19 @@ func (api *API) AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(ctx context.Cont
|
|||
kp.AccountsAddresses = append(kp.AccountsAddresses, types.Address(common.HexToAddress(addr)))
|
||||
}
|
||||
|
||||
migratedKeyPairs, err := api.db.GetMigratedKeyPairByKeyUID(keyUID)
|
||||
knownKeycardsForKeyUID, err := api.db.GetKeycardByKeyUID(keyUID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
added, err := (*api.messenger).AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(ctx, &kp)
|
||||
added, err := (*api.messenger).AddKeycardOrAddAccountsIfKeycardIsAdded(ctx, &kp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Once we migrate a keypair, corresponding keystore files need to be deleted
|
||||
// if the keypair being migrated is not already migrated (in case user is creating a copy of an existing Keycard)
|
||||
if added && len(migratedKeyPairs) == 0 && acc.Type != accounts.AccountTypeWatch {
|
||||
if added && len(knownKeycardsForKeyUID) == 0 && acc.Type != accounts.AccountTypeWatch {
|
||||
for _, addr := range kp.AccountsAddresses {
|
||||
err = api.manager.DeleteAccount(addr)
|
||||
if err != nil {
|
||||
|
@ -332,16 +332,16 @@ func (api *API) RemoveMigratedAccountsForKeycard(ctx context.Context, kcUID stri
|
|||
return (*api.messenger).RemoveMigratedAccountsForKeycard(ctx, kcUID, addresses, clock)
|
||||
}
|
||||
|
||||
func (api *API) GetAllKnownKeycards(ctx context.Context) ([]*keypairs.KeyPair, error) {
|
||||
func (api *API) GetAllKnownKeycards(ctx context.Context) ([]*keycards.Keycard, error) {
|
||||
return api.db.GetAllKnownKeycards()
|
||||
}
|
||||
|
||||
func (api *API) GetAllMigratedKeyPairs(ctx context.Context) ([]*keypairs.KeyPair, error) {
|
||||
return api.db.GetAllMigratedKeyPairs()
|
||||
func (api *API) GetAllKnownKeycardsGroupedByKeyUID(ctx context.Context) ([]*keycards.Keycard, error) {
|
||||
return api.db.GetAllKnownKeycardsGroupedByKeyUID()
|
||||
}
|
||||
|
||||
func (api *API) GetMigratedKeyPairByKeyUID(ctx context.Context, keyUID string) ([]*keypairs.KeyPair, error) {
|
||||
return api.db.GetMigratedKeyPairByKeyUID(keyUID)
|
||||
func (api *API) GetKeycardByKeyUID(ctx context.Context, keyUID string) ([]*keycards.Keycard, error) {
|
||||
return api.db.GetKeycardByKeyUID(keyUID)
|
||||
}
|
||||
|
||||
func (api *API) SetKeycardName(ctx context.Context, kcUID string, kpName string) error {
|
||||
|
@ -364,8 +364,8 @@ func (api *API) DeleteKeycard(ctx context.Context, kcUID string) error {
|
|||
return (*api.messenger).DeleteKeycard(ctx, kcUID, clock)
|
||||
}
|
||||
|
||||
func (api *API) DeleteKeypair(ctx context.Context, keyUID string) error {
|
||||
return api.db.DeleteKeypair(keyUID)
|
||||
func (api *API) DeleteAllKeycardsWithKeyUID(ctx context.Context, keyUID string) error {
|
||||
return api.db.DeleteAllKeycardsWithKeyUID(keyUID)
|
||||
}
|
||||
|
||||
func (api *API) UpdateKeycardUID(ctx context.Context, oldKcUID string, newKcUID string) error {
|
||||
|
|
Loading…
Reference in New Issue