From 2867bb3bc3253957ab3e5613cf0b2b2791cb84e4 Mon Sep 17 00:00:00 2001
From: Ajay Bura <32841439+ajbura@users.noreply.github.com>
Date: Sun, 1 May 2022 13:22:55 +0530
Subject: [PATCH] Session verification by emojis (#513)
* Add option to verify with security key/phrase
* Manually merge #311 by @ginnyTheCat
---
.../emoji-verification/EmojiVerification.jsx | 153 ++++++++++++++++++
.../emoji-verification/EmojiVerification.scss | 35 ++++
src/app/organisms/pw/Dialogs.jsx | 2 +
src/app/organisms/settings/DeviceManage.jsx | 57 +++++--
src/app/organisms/settings/DeviceManage.scss | 17 ++
src/client/action/navigation.js | 7 +
src/client/initMatrix.js | 3 +
src/client/state/cons.js | 2 +
src/client/state/navigation.js | 6 +
9 files changed, 270 insertions(+), 12 deletions(-)
create mode 100644 src/app/organisms/emoji-verification/EmojiVerification.jsx
create mode 100644 src/app/organisms/emoji-verification/EmojiVerification.scss
diff --git a/src/app/organisms/emoji-verification/EmojiVerification.jsx b/src/app/organisms/emoji-verification/EmojiVerification.jsx
new file mode 100644
index 00000000..f56a4672
--- /dev/null
+++ b/src/app/organisms/emoji-verification/EmojiVerification.jsx
@@ -0,0 +1,153 @@
+/* eslint-disable react/prop-types */
+import React, { useState, useEffect } from 'react';
+import PropTypes from 'prop-types';
+import './EmojiVerification.scss';
+import { twemojify } from '../../../util/twemojify';
+
+import initMatrix from '../../../client/initMatrix';
+import cons from '../../../client/state/cons';
+import navigation from '../../../client/state/navigation';
+
+import Text from '../../atoms/text/Text';
+import IconButton from '../../atoms/button/IconButton';
+import Button from '../../atoms/button/Button';
+import Spinner from '../../atoms/spinner/Spinner';
+import Dialog from '../../molecules/dialog/Dialog';
+
+import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
+import { useStore } from '../../hooks/useStore';
+
+function EmojiVerificationContent({ request, requestClose }) {
+ const [sas, setSas] = useState(null);
+ const [process, setProcess] = useState(false);
+ const mountStore = useStore();
+ mountStore.setItem(true);
+
+ const handleChange = () => {
+ if (request.done || request.cancelled) requestClose();
+ };
+
+ useEffect(() => {
+ mountStore.setItem(true);
+ if (request === null) return null;
+ const req = request;
+ req.on('change', handleChange);
+ return () => req.off('change', handleChange);
+ }, [request]);
+
+ const acceptRequest = async () => {
+ setProcess(true);
+ await request.accept();
+
+ const verifier = request.beginKeyVerification('m.sas.v1');
+ verifier.on('show_sas', (data) => {
+ if (!mountStore.getItem()) return;
+ setSas(data);
+ setProcess(false);
+ });
+ await verifier.verify();
+ };
+
+ const sasMismatch = () => {
+ sas.mismatch();
+ setProcess(true);
+ };
+
+ const sasConfirm = () => {
+ sas.confirm();
+ setProcess(true);
+ };
+
+ const renderWait = () => (
+ <>
+