From 546a9234a4afa61147de8aabd598973948b97535 Mon Sep 17 00:00:00 2001 From: vishnukvmd Date: Sun, 13 Nov 2022 13:57:18 +0530 Subject: [PATCH] Allow resetting on 2FA with the mnemonic phrase --- lib/services/user_service.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/services/user_service.dart b/lib/services/user_service.dart index 74239b3f5..df1359c2a 100644 --- a/lib/services/user_service.dart +++ b/lib/services/user_service.dart @@ -1,7 +1,9 @@ // @dart=2.9 +import 'package:bip39/bip39.dart' as bip39; import 'package:dio/dio.dart'; import 'package:ente_auth/core/configuration.dart'; +import 'package:ente_auth/core/constants.dart'; import 'package:ente_auth/core/event_bus.dart'; import 'package:ente_auth/core/network.dart'; import 'package:ente_auth/events/user_details_changed_event.dart'; @@ -620,6 +622,14 @@ class UserService { await dialog.show(); String secret; try { + if (recoveryKey.contains(' ')) { + if (recoveryKey.split(' ').length != mnemonicKeyWordCount) { + throw AssertionError( + 'recovery code should have $mnemonicKeyWordCount words', + ); + } + recoveryKey = bip39.mnemonicToEntropy(recoveryKey); + } secret = Sodium.bin2base64( await CryptoUtil.decrypt( Sodium.base642bin(encryptedSecret),