Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add Verify Identity Dialog component and integrate into drawer

AmanRajSinghMouryadc845b3f0459
diff --git a/mobile/apps/locker/lib/ui/components/verify_identity_dialog.dart b/mobile/apps/locker/lib/ui/components/verify_identity_dialog.dart
new file mode 100644
index 0000000000..c7892bc88b
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/components/verify_identity_dialog.dart
@@ -0,0 +1,179 @@
+import "dart:convert";
+
+import "package:bip39/bip39.dart" as bip39;
+import "package:crypto/crypto.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:ente_ui/components/title_bar_title_widget.dart";
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:ente_ui/utils/toast_util.dart";
+import "package:flutter/material.dart";
+import "package:flutter/services.dart";
+import "package:locker/services/configuration.dart";
+import "package:share_plus/share_plus.dart";
+
+class VerifyIdentityDialog extends StatelessWidget {
+ const VerifyIdentityDialog({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ final publicKey = Configuration.instance.getKeyAttributes()!.publicKey;
+ final verificationID = _generateVerificationID(publicKey);
+
+ return Dialog(
+ backgroundColor: colorScheme.backgroundElevated2,
+ insetPadding: const EdgeInsets.symmetric(horizontal: 24, vertical: 24),
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(24),
+ ),
+ child: Container(
+ constraints: const BoxConstraints(maxWidth: 400),
+ padding: const EdgeInsets.all(24),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ TitleBarTitleWidget(
+ title: context.strings.verifyIDLabel,
+ ),
+ GestureDetector(
+ onTap: () => Navigator.of(context).pop(),
+ child: Container(
+ padding: const EdgeInsets.all(8),
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ color: colorScheme.fillFaint,
+ ),
+ child: Icon(
+ Icons.close,
+ size: 20,
+ color: colorScheme.textMuted,
+ ),
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 16),
+ Text(
+ context.strings.thisIsYourVerificationId,
+ style: textTheme.body.copyWith(
+ color: colorScheme.textMuted,
+ ),
+ ),
+ const SizedBox(height: 24),
+ _buildVerificationIDWidget(
+ context,
+ verificationID,
+ ),
+ const SizedBox(height: 16),
+ Text(
+ context.strings.someoneSharingAlbumsWithYouShouldSeeTheSameId,
+ style: textTheme.body.copyWith(
+ color: colorScheme.textMuted,
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget _buildVerificationIDWidget(
+ BuildContext context,
+ String verificationID,
+ ) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ return GestureDetector(
+ onTap: () => _shareVerificationID(context, verificationID),
+ child: Container(
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(16),
+ color: colorScheme.primary700,
+ ),
+ child: Stack(
+ children: [
+ Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 22,
+ vertical: 24,
+ ),
+ child: SelectableText(
+ verificationID,
+ style: textTheme.body.copyWith(
+ color: Colors.white,
+ fontFamily: "monospace",
+ letterSpacing: 0.5,
+ height: 1.5,
+ ),
+ ),
+ ),
+ Positioned(
+ right: 0,
+ top: 0,
+ child: IconButton(
+ onPressed: () => _copyToClipboard(context, verificationID),
+ visualDensity: VisualDensity.compact,
+ icon: Icon(
+ Icons.copy_rounded,
+ size: 20,
+ color: colorScheme.primary500,
+ ),
+ tooltip: "Copy to clipboard",
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ String _generateVerificationID(String publicKey) {
+ final inputBytes = base64.decode(publicKey);
+ final shaValue = sha256.convert(inputBytes);
+ return bip39.generateMnemonic(
+ strength: 256,
+ randomBytes: (int size) {
+ return Uint8List.fromList(shaValue.bytes);
+ },
+ );
+ }
+
+ Future<void> _copyToClipboard(
+ BuildContext context,
+ String verificationID,
+ ) async {
+ await Clipboard.setData(ClipboardData(text: verificationID));
+ if (context.mounted) {
+ showShortToast(
+ context,
+ context.strings.recoveryKeyCopiedToClipboard,
+ );
+ }
+ }
+
+ Future<void> _shareVerificationID(
+ BuildContext context,
+ String verificationID,
+ ) async {
+ await SharePlus.instance.share(
+ ShareParams(
+ text: verificationID,
+ ),
+ );
+ }
+}
+
+Future<void> showVerifyIdentityDialog(BuildContext context) {
+ return showDialog(
+ context: context,
+ builder: (BuildContext context) {
+ return const VerifyIdentityDialog();
+ },
+ );
+}
diff --git a/mobile/apps/locker/lib/ui/drawer/drawer_page.dart b/mobile/apps/locker/lib/ui/drawer/drawer_page.dart
index bb2d9cd6b6..e4b354785e 100644
--- a/mobile/apps/locker/lib/ui/drawer/drawer_page.dart
+++ b/mobile/apps/locker/lib/ui/drawer/drawer_page.dart
@@ -7,6 +7,7 @@ import "package:locker/events/user_details_refresh_event.dart";
import "package:locker/services/configuration.dart";
import "package:locker/ui/components/legacy_collections_trash_widget.dart";
import "package:locker/ui/components/usage_card_widget.dart";
+import "package:locker/ui/components/verify_identity_dialog.dart";
import "package:locker/ui/drawer/app_version_widget.dart";
import "package:locker/ui/drawer/drawer_title_bar_widget.dart";
import "package:locker/ui/drawer/settings_widgets.dart";
@@ -47,22 +48,26 @@ class DrawerPage extends StatelessWidget {
if (hasLoggedIn) {
contents.add(
- Container(
- padding: const EdgeInsets.symmetric(horizontal: 8),
- child: Align(
- alignment: Alignment.centerLeft,
- child: AnimatedBuilder(
- // [AnimatedBuilder] accepts any [Listenable] subtype.
- animation: emailNotifier,
- builder: (BuildContext context, Widget? child) {
- return Text(
- emailNotifier.value!,
- style: enteTextTheme.body.copyWith(
- color: colorScheme.textMuted,
- overflow: TextOverflow.ellipsis,
- ),
- );
- },
+ GestureDetector(
+ onDoubleTap: () => showVerifyIdentityDialog(context),
+ onLongPress: () => showVerifyIdentityDialog(context),
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 8),
+ child: Align(
+ alignment: Alignment.centerLeft,
+ child: AnimatedBuilder(
+ // [AnimatedBuilder] accepts any [Listenable] subtype.
+ animation: emailNotifier,
+ builder: (BuildContext context, Widget? child) {
+ return Text(
+ emailNotifier.value!,
+ style: enteTextTheme.body.copyWith(
+ color: colorScheme.textMuted,
+ overflow: TextOverflow.ellipsis,
+ ),
+ );
+ },
+ ),
),
),
),
diff --git a/mobile/packages/sharing/lib/verify_identity_dialog.dart b/mobile/packages/sharing/lib/verify_identity_dialog.dart
index 0d132622e1..d41ef3d665 100644
--- a/mobile/packages/sharing/lib/verify_identity_dialog.dart
+++ b/mobile/packages/sharing/lib/verify_identity_dialog.dart
@@ -193,6 +193,7 @@ class _VerifyIdentityDialogState extends State<VerifyIdentityDialog> {
String bottomText,
) {
return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
@@ -225,7 +226,7 @@ class _VerifyIdentityDialogState extends State<VerifyIdentityDialog> {
Widget _verificationIDWidget(BuildContext context, String publicKey) {
final colorScheme = getEnteColorScheme(context);
- final textStyle = getEnteTextTheme(context);
+ final textTheme = getEnteTextTheme(context);
final String verificationID = _generateVerificationID(publicKey);
return GestureDetector(
onTap: () async {
@@ -245,14 +246,23 @@ class _VerifyIdentityDialogState extends State<VerifyIdentityDialog> {
},
child: Container(
decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(8),
+ borderRadius: BorderRadius.circular(16),
color: colorScheme.primary700,
),
- padding: const EdgeInsets.all(20),
+ padding: const EdgeInsets.symmetric(
+ horizontal: 22,
+ vertical: 24,
+ ),
width: double.infinity,
child: Text(
verificationID,
- style: textStyle.bodyBold.copyWith(color: Colors.white),
+ style: textTheme.body.copyWith(
+ color: Colors.white,
+ fontFamily: 'monospace',
+ letterSpacing: 0.5,
+ height: 1.5,
+ ),
+ textAlign: TextAlign.justify,
),
),
);