fix: recovering/migrating keypairs fixes
- fixed issue with displaying 3 words name on the login screen after recovering from waku - fixed inability to delete account after recovering from waku
This commit is contained in:
parent
011a170a03
commit
e87e9b6f81
|
@ -31,6 +31,10 @@ type Account struct {
|
||||||
CustomizationColorClock uint64 `json:"-"`
|
CustomizationColorClock uint64 `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Account) RefersToKeycard() bool {
|
||||||
|
return a.KeycardPairing != ""
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Account) ToProtobuf() *protobuf.MultiAccount {
|
func (a *Account) ToProtobuf() *protobuf.MultiAccount {
|
||||||
var colorHashes []*protobuf.MultiAccount_ColorHash
|
var colorHashes []*protobuf.MultiAccount_ColorHash
|
||||||
for _, index := range a.ColorHash {
|
for _, index := range a.ColorHash {
|
||||||
|
|
|
@ -497,7 +497,7 @@ func (m *Messenger) backupProfile(ctx context.Context, clock uint64) ([]*protobu
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) backupKeypairs() ([]*protobuf.Backup, error) {
|
func (m *Messenger) backupKeypairs() ([]*protobuf.Backup, error) {
|
||||||
keypairs, err := m.settings.GetActiveKeypairs()
|
keypairs, err := m.settings.GetAllKeypairs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,7 +250,7 @@ func (m *Messenger) handleKeypair(message *protobuf.SyncKeypair) error {
|
||||||
}
|
}
|
||||||
// If user is recovering his account via seed phrase, but the backed up messages indicate that the profile keypair
|
// If user is recovering his account via seed phrase, but the backed up messages indicate that the profile keypair
|
||||||
// is a keycard related profile, then we need to remove related profile keycards (only profile, other keycards should remain).
|
// is a keycard related profile, then we need to remove related profile keycards (only profile, other keycards should remain).
|
||||||
if multiAcc != nil && multiAcc.KeyUID == message.KeyUid && multiAcc.KeycardPairing == "" && len(message.Keycards) > 0 {
|
if multiAcc != nil && multiAcc.KeyUID == message.KeyUid && !multiAcc.RefersToKeycard() && len(message.Keycards) > 0 {
|
||||||
message.Keycards = []*protobuf.SyncKeycard{}
|
message.Keycards = []*protobuf.SyncKeycard{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3247,13 +3247,13 @@ func mapSyncAccountToAccount(message *protobuf.SyncAccount, accountOperability a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) resolveAccountOperability(syncAcc *protobuf.SyncAccount, syncKpMigratedToKeycard bool,
|
func (m *Messenger) resolveAccountOperability(syncAcc *protobuf.SyncAccount, recoverinrecoveringFromWakuInitiatedByKeycard bool,
|
||||||
dbKpMigratedToKeycard bool, accountReceivedFromLocalPairing bool) (accounts.AccountOperable, error) {
|
syncKpMigratedToKeycard bool, dbKpMigratedToKeycard bool, accountReceivedFromLocalPairing bool) (accounts.AccountOperable, error) {
|
||||||
if accountReceivedFromLocalPairing {
|
if accountReceivedFromLocalPairing {
|
||||||
return accounts.AccountOperable(syncAcc.Operable), nil
|
return accounts.AccountOperable(syncAcc.Operable), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if syncKpMigratedToKeycard || m.account.KeyUID == syncAcc.KeyUid {
|
if syncKpMigratedToKeycard || recoverinrecoveringFromWakuInitiatedByKeycard && m.account.KeyUID == syncAcc.KeyUid {
|
||||||
return accounts.AccountFullyOperable, nil
|
return accounts.AccountFullyOperable, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3534,18 +3534,19 @@ func (m *Messenger) handleSyncKeypair(message *protobuf.SyncKeypair, fromLocalPa
|
||||||
}
|
}
|
||||||
|
|
||||||
syncKpMigratedToKeycard := len(message.Keycards) > 0
|
syncKpMigratedToKeycard := len(message.Keycards) > 0
|
||||||
|
recoveringFromWaku := message.SyncedFrom == accounts.SyncedFromBackup
|
||||||
|
|
||||||
|
multiAcc, err := m.multiAccounts.GetAccount(kp.KeyUID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
recoverinrecoveringFromWakuInitiatedByKeycard := recoveringFromWaku && multiAcc != nil && multiAcc.RefersToKeycard()
|
||||||
for _, sAcc := range message.Accounts {
|
for _, sAcc := range message.Accounts {
|
||||||
if message.SyncedFrom == accounts.SyncedFromBackup && kp.Type == accounts.KeypairTypeProfile {
|
accountOperability, err := m.resolveAccountOperability(sAcc,
|
||||||
// if a profile keypair is coming from backup, we're handling within this block the case when a recovering
|
recoverinrecoveringFromWakuInitiatedByKeycard,
|
||||||
// was inititiated via keycard, while backed up profile keypair data refers to a regular profile
|
syncKpMigratedToKeycard,
|
||||||
multiAcc, err := m.multiAccounts.GetAccount(kp.KeyUID)
|
dbKeypair != nil && dbKeypair.MigratedToKeycard(),
|
||||||
if err != nil {
|
fromLocalPairing)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
syncKpMigratedToKeycard = multiAcc != nil && multiAcc.KeycardPairing != ""
|
|
||||||
}
|
|
||||||
accountOperability, err := m.resolveAccountOperability(sAcc, syncKpMigratedToKeycard,
|
|
||||||
dbKeypair != nil && dbKeypair.MigratedToKeycard(), fromLocalPairing)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -3554,7 +3555,7 @@ func (m *Messenger) handleSyncKeypair(message *protobuf.SyncKeypair, fromLocalPa
|
||||||
kp.Accounts = append(kp.Accounts, acc)
|
kp.Accounts = append(kp.Accounts, acc)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !fromLocalPairing {
|
if !fromLocalPairing && !recoverinrecoveringFromWakuInitiatedByKeycard {
|
||||||
if kp.Removed ||
|
if kp.Removed ||
|
||||||
dbKeypair != nil && !dbKeypair.MigratedToKeycard() && syncKpMigratedToKeycard {
|
dbKeypair != nil && !dbKeypair.MigratedToKeycard() && syncKpMigratedToKeycard {
|
||||||
// delete all keystore files
|
// delete all keystore files
|
||||||
|
|
|
@ -95,16 +95,9 @@ func (m *Messenger) SaveSyncDisplayName(displayName string, clock uint64) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
preferredNameClock, err := m.settings.GetSettingLastSynced(settings.PreferredName)
|
|
||||||
if err != nil {
|
m.account.Name = displayName
|
||||||
return err
|
return m.multiAccounts.SaveAccount(*m.account)
|
||||||
}
|
|
||||||
// check clock of preferred name to avoid override account name
|
|
||||||
if preferredNameClock < clock {
|
|
||||||
m.account.Name = displayName
|
|
||||||
return m.multiAccounts.SaveAccount(*m.account)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidateBio(bio *string) error {
|
func ValidateBio(bio *string) error {
|
||||||
|
|
Loading…
Reference in New Issue