Merge pull request #140 from ente-io/mnemonic_passphrase

Add support to show mnemonic recovery key
This commit is contained in:
Neeraj Gupta 2021-11-15 14:05:49 +05:30 committed by GitHub
commit b839589a50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 3 deletions

View file

@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io' as io;
import 'dart:typed_data';
import 'package:bip39/bip39.dart' as bip39;
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_sodium/flutter_sodium.dart';
import 'package:logging/logging.dart';
@ -28,6 +29,8 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:super_logging/super_logging.dart';
import 'package:uuid/uuid.dart';
import 'constants.dart';
class Configuration {
Configuration._privateConstructor();
@ -265,6 +268,14 @@ class Configuration {
}
Future<void> recover(String recoveryKey) async {
// check if user has entered mnemonic code
if (recoveryKey.contains(' ')) {
if (recoveryKey.split(' ').length != kMnemonicKeyWordCount) {
throw AssertionError(
'recovery code should have $kMnemonicKeyWordCount words');
}
recoveryKey = bip39.mnemonicToEntropy(recoveryKey);
}
final attributes = getKeyAttributes();
Uint8List masterKey;
try {

View file

@ -20,3 +20,7 @@ const String kLivePhotoToastCounterKey = "show_live_photo_toast";
const kThumbnailDiskLoadDeferDuration = Duration(milliseconds: 40);
const kThumbnailServerLoadDeferDuration = Duration(milliseconds: 80);
// 256 bit key maps to 24 words
// https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#Generating_the_mnemonic
const kMnemonicKeyWordCount = 24;

View file

@ -1,10 +1,12 @@
import 'dart:io' as io;
import 'dart:ui';
import 'package:bip39/bip39.dart' as bip39;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/constants.dart';
import 'package:photos/utils/toast_util.dart';
import 'package:share_plus/share_plus.dart';
@ -39,7 +41,11 @@ class _RecoveryKeyDialogState extends State<RecoveryKeyDialog> {
@override
Widget build(BuildContext context) {
final recoveryKey = widget.recoveryKey;
final String recoveryKey = bip39.entropyToMnemonic(widget.recoveryKey);
if (recoveryKey.split(' ').length != kMnemonicKeyWordCount) {
throw AssertionError(
'recovery code should have $kMnemonicKeyWordCount words');
}
List<Widget> actions = [];
if (!_hasTriedToSave) {
actions.add(TextButton(

View file

@ -86,8 +86,13 @@ class _RecoveryPageState extends State<RecoveryPage> {
);
} catch (e) {
await dialog.hide();
showErrorDialog(context, "incorrect recovery key",
"the recovery key you entered is incorrect");
String errMessage =
'the recovery key you entered is incorrect';
if (e is AssertionError) {
errMessage = '$errMessage : ${e.message}';
}
showErrorDialog(
context, "incorrect recovery key", errMessage);
}
}
: null,

View file

@ -50,6 +50,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.73"
bip39:
dependency: "direct main"
description:
name: bip39
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.6"
boolean_selector:
dependency: transitive
description:
@ -492,6 +499,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.5"
hex:
dependency: transitive
description:
name: hex
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
html:
dependency: transitive
description:
@ -827,6 +841,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
pointycastle:
dependency: transitive
description:
name: pointycastle
url: "https://pub.dartlang.org"
source: hosted
version: "3.4.0"
process:
dependency: transitive
description:

View file

@ -21,6 +21,7 @@ dependencies:
animate_do: ^2.0.0
archive: ^3.1.2
background_fetch: ^1.0.1
bip39: ^1.0.6
cached_network_image: ^3.0.0
chewie:
path: thirdparty/chewie