Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] ABW-2121 Save accounts needing recovery in UserDefaults #685

Merged
merged 100 commits into from
Sep 4, 2023

Conversation

CyonAlexRDX
Copy link
Contributor

@CyonAlexRDX CyonAlexRDX commented Aug 24, 2023

ABW-2121 Mnemonic recovery and backup

(Also included in PR is ABW-2067)

Description

  • Change UserDefaultsClient's Key to not be a typealias for String, but rather an enum, which conforms to CaseIterable so that we easily can delete all values
  • Introduce a Debug Feature visible from Debug settings which allows you to during runtime in the app inspect the contents of UserDefaults
  • During Restore wallet flow, all accounts controlled by a mnemonic the user skipped to import will be saved in UserDefaults list under key .accountsThatNeedRecovery (Olympia accounts only, mnemonic controlling babylon accounts cannot be skipped)
  • Show "Recovery of seed phrase required" button on Account cards in Home (AccountList.Row), and in AccountDetails if UserDefaults value for key .accountsThatNeedRecovery contains the account in question
  • Show "Back up this account's seed phrase" button on Account cards in Home (AccountList.Row), and in AccountDetails if all these conditions are met:
    • The account is controlled by an Olympia device factor source (mnemonic)
    • The account has funds in it
    • The account is not marked "Recovery of seed phrase required" (i.e. the account is not in the .accountsThatNeedRecovery list (UserDefaults))
    • UserDefaults value for key .mnemonicsUserClaimsToHaveBackedUp does not contain the device FactorSourceID already
  • We add mnemonics to .mnemonicsUserClaimsToHaveBackedUp list and remove accounts from the .accountsThatNeedRecovery list when:
    • Mnemonics imported during Import Olympia wallet flow
    • Mnemonics imported during ImportMnemonicsControllingAccounts flow (part of Restore wallet flow)
    • When user presses "I've backed it up" button in dialog displayed to user when they leave Reveal Seed Phrase screen (which is presented to them if they press the "Back up this account's seed phrase" button in AccountDetails)

Demo

See demo on Slack (demo of Setup + Test scenario 1)

Test Restore wallet (Profile and Mnemonics) flow

Setup

DELETE wallet

  • Create a new wallet, create THREE babylon accounts, do not use faucet on any account yet
  • Use faucet with one account, so one babylon account has XRD and the others do not.
  • VERIFY that the account with XRD in it has a "Back up..." prompt on their cards in Home/Account Details, and that the account without has no prompt on it.
  • From HOME list, press the "Back up" button on the card
  • VERIFY that you are prompted for biometrics and that Backup Seed Phrase screen opens directly
  • Write down Babylon Mnemonic e.g. Notes in iPhone (easy to copy paste between your Mac and iPhone if you are signed in with same iCloud account)
  • Close screen, select "I've backed up" button on dialog when dismissing view
  • VERIFY that the "Back up..." prompt is not displayed on ANY account
  • Use faucet with second account
  • VERIFY that the "Back up..." prompt is not displayed on ANY account
  • Go to Settings -> Account Security & Settings -> Seed Phrases -> Babylon/main mnemonic -> Back, VERIFY that you do NOT get a prompt about backing up the mnemonic (since you have already said that you have backed it up)
  • Create TWO different Olympia wallets (each with TWO software accounts) (see this guide for how to)
  • Make sure to have written down BOTH Olympia mnemonics, e.g. Notes in iPhone. One mnemonic should have 12 words, the other should have 18 words (if you followed guide above....)
  • Import the first Olympia wallet in Babylon wallet
  • VERIFY that the "Back up..." prompt is not displayed on ANY account
  • Import the second Olympia wallet in Babylon wallet
  • VERIFY that the "Back up..." prompt is not displayed on ANY account
  • Use faucet on one of the Olympia accounts from FIRST Olympia wallet
  • VERIFY that the "Back up..." prompt is not displayed on ANY account
  • Use faucet on one of the Olympia accounts from SECOND Olympia wallet
  • VERIFY that the "Back up..." prompt is not displayed on ANY account
  • Export Profile to file, use encryption
  • Make sure to use faucet so that each mnemonic controls one account with funds in it and one without funds in it
  • Delete wallet
  • Restore wallet from encrypted Profile backup
  • PERFORM ALL TEST SCENARIOS BELOW

Test scenario 1

TEST:

  • After having imported the Babylon ("Main") mnemonic
  • SKIP Olympia mnemonic ("first")
  • SKIP Olympia mnemonic ("second")
  • VERIFY None of the Babylon accounts have ANY prompts
  • VERIFY "Recovery of seed phrase required" prompt is displayed on ALL Legacy accounts (Both accounts from Both Olympia wallets)
  • Send XRD from one of the babylon mnemonic accounts
  • VERIFY that you could send XRD...
  • Press "Recovery of.." prompt in Home -> the flow importing mnemonics (plural) will start
  • Recover FIRST but not SECOND Olympia mnemonic
  • VERIFY that none of the accounts controlled by FIRST Olympia mnemonic have the "Recovery of..." prompt on them
  • VERIFY that both the accounts controlled by the SECOND Olympia mnemonic HAS the "Recovery of.." prompt on them
  • VERIFY that NO account has a "Back up..." prompt on them
  • Send XRD from one of the accounts controlled by this FIRST Olympia Mnemonic
  • VERIFY that you could send XRD...
  • Recover the other Olympia mnemonic, verify that no account has ANY prompt what so ever.
  • Send XRD from one of the accounts controlled by this SECOND Olympia Mnemonic
  • VERIFY that you could send XRD...
  • FORCE QUIT APP (testing that mnemonic is indeed persisted....)
  • VERIFY that NO account has ANY prompt what so ever.
  • VERIFY that you can send XRD from a Babylon account, one account controlled by FIRST Olympia mnemonic, and lastly also that you can send XRD from an account controlled by the SECOND Olympia mnemonic

Test scenario 2

DELETE wallet, and restore wallet from encrypted backup

TEST:
Identical to scenario 1 - recover first ONLY the Babylon mnemonic (skip BOTH olympia), verify all things according to test scenario 1 above until you reach - Recover FIRST but not SECOND Olympia mnemonic but here reverse the order, i.e. SKIP first, but recover SECOND, verify the expected state (the analogue/inversed expected state)

Test scenario 3

DELETE wallet, and restore wallet from encrypted backup

TEST:

  • Import ALL mnemonics part of "Restore wallet" flow
  • Verify that NO account has ANY prompts what so ever
  • Send XRD from one of the babylon mnemonic accounts
  • VERIFY that you could send XRD...
  • Send XRD from one of the accounts controlled by this FIRST Olympia Mnemonic
  • VERIFY that you could send XRD...
  • Recover the other Olympia mnemonic, verify that no account has ANY prompt what so ever.
  • Send XRD from one of the accounts controlled by this SECOND Olympia Mnemonic
  • VERIFY that you could send XRD...

Test scenario 4

DELETE wallet, and restore wallet from encrypted backup

TEST:

  • Import Main and FIRST Olympia mnemonic (i.e. skip last/second)
  • VERIFY that none of the babylon accounts has any prompts on them
  • VERIFY that non of the Olympia accounts controlled by FIRST mnemonic has any prompts on them
  • VERIFY that all/both Olympia accounts controlled by the SESCOND menmonic has the "Recovery of..." prompts on them
  • Recover that second Olmypia mnemonic
  • VERIFY that NO accounts has ANY prompts on them

Test scenario 5

DELETE wallet, and restore wallet from encrypted backup

TEST:

  • Import Main and SKIP first Olympia mnemonic, but import SECOND Olympia mnemonic
  • Follow steps of Test scenario 4, verify the expected state (the analogue/inversed expected state)

Test scenario 6

  • Import Ledger accounts
  • VERIFY that no prompt at all is shown on legacy ledger account
  • Use faucet on it/them to have XRD
  • VERIFY that no prompt at all is shown on legacy ledger account

Test scenario 7

  • Create Babylon Ledger accounts
  • VERIFY that no prompt at all is shown on ledger account
  • Use faucet on it/them to have XRD
  • VERIFY that no prompt at all is shown on ledger account

@CyonAlexRDX CyonAlexRDX marked this pull request as ready for review September 4, 2023 10:46

func delay() async {
// navigation bug if we try to "deep link" too fast..
try? await clock.sleep(for: .milliseconds(900))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh... needed unfortunately. SwiftUI :/

}

// FIXME: Refactor account security prompts to share logic between this reducer and Row+Reducer (AccountList)
private func checkAccountSecurityPromptStatus(state: inout State) -> EffectTask<Action> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah... not great, really should merge with AccountList, but no time :/

Copy link
Contributor

@kugel3 kugel3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, only stylistic comments. Will test after standup

@CyonAlexRDX CyonAlexRDX merged commit 04cb429 into main Sep 4, 2023
6 checks passed
@CyonAlexRDX CyonAlexRDX deleted the ABW-2121_accounts_needing_recovery_in_UserDefaults branch September 4, 2023 17:11
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants