mnemonic_backup_flow library

Recovery-phrase reveal, verification and import screens for Flutter wallets.

Start with showMnemonicBackupFlow for the whole backup, or use MnemonicRevealScreen, MnemonicVerifyScreen and MnemonicImportScreen on their own. Every screen takes a ScreenProtection, which the app implements with the screenshot plugin it already uses, and a MnemonicBackupStrings for translated text.

Classes

MnemonicBackupStrings
Every piece of user-facing text in the flow, so an app can translate it.
MnemonicImportScreen
Takes a phrase the user types or pastes, validates it, and hands it back as MnemonicWords.
MnemonicRevealScreen
Shows the phrase, numbered, once the screen protection is active and the user has asked to see it, and hides it while the app is not in the foreground so the app switcher snapshot does not carry it.
MnemonicVerifyScreen
Asks for the words at a few distinct positions, one at a time, as multiple choice.
MnemonicWords
A recovery phrase held in memory.
ScreenProtection
Keeps the recovery phrase out of screenshots and screen recordings while it is on screen.
SensitiveClipboard
Copies text to the clipboard and removes it again after clearAfter, if it is still there.
VerificationChallenge
One question in the backup check: which word sits at position?

Enums

Language
BIP39: Since the vast majority of BIP39 wallets supports only the English wordlist, it is strongly discouraged to use non-English wordlists for generating the mnemonic sentences. If you still feel your application really needs to use a localized wordlist, use one of the following instead of inventing your own.
MnemonicBackupResult
How a backup flow ended.
MnemonicFormatProblem
Why a typed or pasted phrase was rejected.

Functions

generateChallenges(List<String> words, {required List<String> wordList, int count = 3, int choiceCount = 4, Random? random}) → List<VerificationChallenge>
Picks count distinct positions of the phrase and builds a multiple-choice challenge for each, with decoys drawn from wordList that do not appear in the phrase.
showMnemonicBackupFlow(BuildContext context, {required MnemonicWords words, required Future<bool> authenticate(BuildContext context), required ScreenProtection screenProtection, MnemonicBackupStrings strings = const MnemonicBackupStrings(), int challengeCount = 3, bool allowCopy = false, bool obscureUntilShown = true, Duration? protectionTimeout = const Duration(seconds: 15)}) → Future<MnemonicBackupResult>
Runs the whole backup: authenticate, reveal, verify.